| 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(); |
|---|
| 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 | } |
|---|