Changeset 4133

Show
Ignore:
Timestamp:
09/19/06 19:47:17 (2 years ago)
Author:
bergie
Message:

Yet untested substyle support for role_midgardelement by Jerry

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/support/Role_Midgardelement/Midgardelement.php

    r3308 r4133  
    5050        $style_name = $pkg->getPackage(); 
    5151        $element_name = str_replace('.php', '', basename($file)); 
    52          
     52 
     53        /* 
     54         Get style elements path from baseinstalldir attribute 
     55         ie. /template_Textual/layouts 
     56        */ 
     57        $parts = explode("/",$atts["baseinstalldir"]); 
     58        $path_items = array(); 
     59        for($i=0;$i<count($parts);$i++) { 
     60            if(!empty($parts[$i])) 
     61                $path_items[] = $parts[$i]; 
     62        } 
     63 
     64        /* 
     65          We assume that this is the root style 
     66          ie. template_Textual 
     67        */ 
     68        $rootStyleName = $path_items[0]; 
     69 
     70        /* 
     71          Collect rest of the path to own array, 
     72          we will check if exists or create all 
     73          these. 
     74        */ 
     75        $subStyleNames = array(); 
     76        for($i=1;$i<count($path_items);$i++) { 
     77            $subStyleNames[] = $path_items[$i]; 
     78        } 
     79 
    5380        // Initialize Midgard session 
    5481        mgd_config_init($init_file); 
    55          
    56         $qb = new MidgardQueryBuilder('midgard_style'); 
    57         $qb->add_constraint('up', '=', 0); 
    58         $qb->add_constraint('name', '=', $style_name); 
    59         $styles = @$qb->execute(); 
    60          
    61         if (count($styles) == 0) 
    62         { 
    63             // Create missing style template 
    64             $new_style = new midgard_style(); 
    65             $new_style->up = 0; 
    66             $new_style->name = $style_name; 
    67             $stat = $new_style->create(); 
     82 
     83        /* 
     84          Theres no substyles so lets create the element in ROOT 
     85        */ 
     86        if(empty($subStyleNames)) { 
     87 
     88            $qb = new MidgardQueryBuilder('midgard_style'); 
     89            $qb->add_constraint('up', '=', 0); 
     90            $qb->add_constraint('name', '=', $style_name); 
     91            $styles = @$qb->execute(); 
     92 
     93            if (count($styles) == 0) 
     94            { 
     95                // Create missing style template 
     96                $new_style = new midgard_style(); 
     97                $new_style->up = 0; 
     98                $new_style->name = $style_name; 
     99                $stat = $new_style->create(); 
     100                if (!$stat) 
     101                { 
     102                    PEAR::raiseError("Failed to create Midgard style \"{$style_name}\", check config directives in the Midgard conf.d file \"{$init_file}\". Error was " . mgd_errstr()); 
     103                } 
     104                $style = new midgard_style(); 
     105                $style->get_by_id($new_style->id); 
     106            } 
     107            else 
     108            { 
     109                $style = $styles[0]; 
     110            } 
     111 
     112            // Aegir v1 compatibility fix 
     113            $style->parameter('Display', 'Shared', 'YES'); 
     114 
     115            $qb = new MidgardQueryBuilder('midgard_element'); 
     116            $qb->add_constraint('style', '=', $style->id); 
     117            $qb->add_constraint('name', '=', $element_name); 
     118            $elements = @$qb->execute(); 
     119 
     120            if (count($elements) == 0) 
     121            { 
     122                // Create missing element 
     123                $new_element = new midgard_element(); 
     124                $new_element->style = $style->id; 
     125                $new_element->name = $element_name; 
     126                $stat = $new_element->create(); 
     127                if (!$stat) 
     128                { 
     129                    PEAR::raiseError("Failed to create element \"{$element_name}\" under Midgard style \"{$style->name}\", error " . mgd_errstr()); 
     130                } 
     131                $element = new midgard_element(); 
     132                $element->get_by_id($new_element->id); 
     133            } 
     134            else 
     135            { 
     136                $element = $elements[0]; 
     137            } 
     138 
     139            // Load contents of the element file 
     140            $element->value = file_get_contents($installing_paths[3]); 
     141            $stat = $element->update(); 
    68142            if (!$stat) 
    69143            { 
    70                 PEAR::raiseError("Failed to create Midgard style \"{$style_name}\", check config directives in the Midgard conf.d file \"{$init_file}\". Error was " . mgd_errstr()); 
    71             } 
    72             $style = new midgard_style(); 
    73             $style->get_by_id($new_style->id); 
    74         } 
    75         else 
    76         { 
    77             $style = $styles[0]; 
    78         } 
    79          
    80         // Aegir v1 compatibility fix 
    81         //$style->parameter('Display', 'Shared', 'YES'); 
    82          
    83         $qb = new MidgardQueryBuilder('midgard_element'); 
    84         $qb->add_constraint('style', '=', $style->id); 
    85         $qb->add_constraint('name', '=', $element_name); 
    86         $elements = @$qb->execute(); 
    87          
    88         if (count($elements) == 0) 
    89         { 
    90             // Create missing element 
    91             $new_element = new midgard_element(); 
    92             $new_element->style = $style->id; 
    93             $new_element->name = $element_name; 
    94             $stat = $new_element->create(); 
    95             if (!$stat) 
    96             { 
    97                 PEAR::raiseError("Failed to create element \"{$element_name}\" under Midgard style \"{$style->name}\", error " . mgd_errstr()); 
    98             } 
    99             $element = new midgard_element(); 
    100             $element->get_by_id($new_element->id); 
    101         } 
    102         else 
    103         { 
    104             $element = $elements[0]; 
    105         } 
    106  
    107         // Load contents of the element file 
    108         $element->value = file_get_contents($installing_paths[3]); 
    109         $stat = $element->update(); 
    110         if (!$stat) 
    111         { 
    112             PEAR::raiseError("Failed to update element \"{$element_name}\" under Midgard style \"{$style->name}\", error " . mgd_errstr()); 
    113             die(); 
     144                PEAR::raiseError("Failed to update element \"{$element_name}\" under Midgard style \"{$style->name}\", error " . mgd_errstr()); 
     145                die(); 
     146            } 
     147 
     148        } else { 
     149 
     150            $qb = new MidgardQueryBuilder('midgard_style'); 
     151            $qb->add_constraint('name', '=', $rootStyleName); 
     152            $styles = @$qb->execute(); 
     153 
     154            if(count($styles) == 0) { 
     155                PEAR::raiseError("Failed to find Midgard style \"{$rootStyleName}\", check config directives in the Midgard conf.d file \"{$init_file}\". Error was " . mgd_errstr()); 
     156            } else { 
     157                $root_style = $styles[0]; 
     158 
     159                /* 
     160                  We loop through all the substyles 
     161                  we have collected and check if they exist, 
     162                  Create all that doesn't and finally 
     163                  save the element under the last substyle 
     164                */ 
     165 
     166                $subStyleCount = count($subStyleNames); 
     167                $lastSubStyle = ''; 
     168                $tmpIDs = array(); 
     169                for($i=0;$i<$subStyleCount;$i++) { 
     170                    $parentID = ($i==0)?$root_style->id:$tmpIDs[$i-1]; 
     171 
     172                    $qb = new MidgardQueryBuilder('midgard_style'); 
     173                    $qb->add_constraint('up', '=', $parentID); 
     174                    $qb->add_constraint('name', '=', $subStyleNames[$i]); 
     175                    $sstyles = @$qb->execute(); 
     176 
     177                    if (count($sstyles) == 0) 
     178                    { 
     179                        $new_sstyle = new midgard_style(); 
     180                        $new_sstyle->up = $parentID; 
     181                        $new_sstyle->name = $subStyleNames[$i]; 
     182                        $tmpIDs[$i] = $new_sstyle->id; 
     183 
     184                        $stat = $new_sstyle->create(); 
     185                        if (!$stat) 
     186                        { 
     187                            PEAR::raiseError("Failed to create Midgard style \"{$subStyleNames}\", check config directives in the Midgard conf.d file \"{$init_file}\". Error was " . mgd_errstr()); 
     188                        } 
     189                        $sstyle = new midgard_style(); 
     190                        $sstyle->get_by_id($new_sstyle->id); 
     191                    } 
     192                    else 
     193                    { 
     194                        $sstyle = $sstyles[0]; 
     195                        $tmpIDs[$i] = $sstyle->id; 
     196                    } 
     197 
     198                    if($i==$subStyleCount-1) { 
     199                        $lastSubStyle = $sstyle; 
     200                    } 
     201                } 
     202             
     203                $qb = new MidgardQueryBuilder('midgard_element'); 
     204                $qb->add_constraint('style', '=', $lastSubStyle->id); 
     205                $qb->add_constraint('name', '=', $element_name); 
     206                $elements = @$qb->execute(); 
     207             
     208                if (count($elements) == 0) 
     209                { 
     210                    // Create missing element 
     211                    $new_element = new midgard_element(); 
     212                    $new_element->style = $lastSubStyle->id; 
     213                    $new_element->name = $element_name; 
     214                    $stat = $new_element->create(); 
     215                    if (!$stat) 
     216                    { 
     217                        PEAR::raiseError("Failed to create element \"{$element_name}\" under Midgard style \"{$lastSubStyle->name}\", error " . mgd_errstr()); 
     218                    } 
     219                    $element = new midgard_element(); 
     220                    $element->get_by_id($new_element->id); 
     221                } 
     222                else 
     223                { 
     224                    $element = $elements[0]; 
     225                } 
     226             
     227                $element->value = file_get_contents($installing_paths[3]); 
     228                $stat = $element->update(); 
     229                if (!$stat) 
     230                { 
     231                    PEAR::raiseError("Failed to update element \"{$element_name}\" under Midgard style \"{$style->name}\", error " . mgd_errstr()); 
     232                    die(); 
     233                } 
     234             
     235            } 
    114236        } 
    115237         
  • trunk/support/Role_Midgardelement/package.xml

    r3308 r4133  
    1313        <active>yes</active> 
    1414    </lead> 
    15     <date>2006-04-21</date> 
     15    <developer> 
     16        <name>Jerry Jalava</name> 
     17        <user>w_i</user> 
     18        <email>jerry.jalava@incognito.fi</email> 
     19        <active>yes</active> 
     20    </developer> 
     21    <date>2006-09-19</date> 
    1622    <time>20:55:14</time> 
    1723    <version> 
    18         <release>1.0.3</release> 
     24        <release>1.0.4</release> 
    1925        <api>1.0.0</api> 
    2026    </version>