| 79 | | if (!mgd_is_guid($root_topic_guid)) |
|---|
| 80 | | { |
|---|
| 81 | | throw new midgard_admin_sitewizard_exception("Failed to get valid root topic guid from root page parameter GUID: " |
|---|
| 82 | | . $root_topic_guid . " Reason: " . mgd_errstr()); |
|---|
| 83 | | |
|---|
| 84 | | return false; |
|---|
| 85 | | } |
|---|
| 86 | | else |
|---|
| 87 | | { |
|---|
| 88 | | $this->verbose("Getting root topic of page GUID: " . $this->root_page->guid); |
|---|
| 89 | | $this->root_topic = new midgard_topic($root_topic_guid); |
|---|
| | 80 | if (!mgd_is_guid($root_topic_guid)) |
|---|
| | 81 | { |
|---|
| | 82 | throw new midgard_admin_sitewizard_exception("Failed to get valid root topic |
|---|
| | 83 | guid from root page parameter GUID: " . $root_topic_guid . " Reason: " . mgd_errstr()); |
|---|
| | 84 | |
|---|
| | 85 | return false; |
|---|
| | 86 | } |
|---|
| | 87 | else |
|---|
| | 88 | { |
|---|
| | 89 | $this->verbose("Getting root topic of page GUID: " . $this->root_page->guid); |
|---|
| | 90 | $this->root_topic = new midgard_topic($root_topic_guid); |
|---|
| | 116 | |
|---|
| | 117 | public function create_index_article($topic_id, $title = '') |
|---|
| | 118 | { |
|---|
| | 119 | $this->verbose("Creating index article for topic ID: " . $topic_id . " Title: " . $title); |
|---|
| | 120 | |
|---|
| | 121 | $article = new midgard_article(); |
|---|
| | 122 | $article->topic = $topic_id; |
|---|
| | 123 | $article->title = $title; |
|---|
| | 124 | $article->name = 'index'; |
|---|
| | 125 | |
|---|
| | 126 | if (!$article->create()) |
|---|
| | 127 | { |
|---|
| | 128 | throw new midgard_admin_sitewizard_exception("Failed to create index article GUID: " |
|---|
| | 129 | . $article->guid . " Reason: " . mgd_errstr()); |
|---|
| | 130 | } |
|---|
| | 131 | else |
|---|
| | 132 | { |
|---|
| | 133 | return true; |
|---|
| | 134 | } |
|---|
| | 135 | |
|---|
| | 136 | return false; |
|---|
| | 137 | } |
|---|
| 156 | | $qb = new midgard_query_builder('midgard_group'); |
|---|
| 157 | | $qb->add_constraint('sitegroup', '=', $this->sitegroup->id); |
|---|
| 158 | | $qb->add_constraint('owner', '=', $owner_group->id); |
|---|
| 159 | | $qb->add_constraint('name', '=', $group_name); |
|---|
| 160 | | |
|---|
| 161 | | $groups = $qb->execute(); |
|---|
| 162 | | |
|---|
| 163 | | if (count($groups) > 0) |
|---|
| 164 | | { |
|---|
| | 179 | $qb = new midgard_query_builder('midgard_group'); |
|---|
| | 180 | $qb->add_constraint('sitegroup', '=', $this->sitegroup->id); |
|---|
| | 181 | $qb->add_constraint('owner', '=', $owner_group->id); |
|---|
| | 182 | $qb->add_constraint('name', '=', $group_name); |
|---|
| | 183 | |
|---|
| | 184 | $groups = $qb->execute(); |
|---|
| | 185 | |
|---|
| | 186 | if (count($groups) > 0) |
|---|
| | 187 | { |
|---|
| 168 | | $this->creation_root_group = $groups[0]; |
|---|
| 169 | | |
|---|
| 170 | | return true; |
|---|
| 171 | | } |
|---|
| 172 | | else |
|---|
| 173 | | { |
|---|
| 174 | | $this->creation_root_group = new midgard_group(); |
|---|
| 175 | | $this->creation_root_group->owner = $owner_group->id; |
|---|
| 176 | | $this->creation_root_group->sitegroup = $this->sitegroup->id; |
|---|
| 177 | | $this->creation_root_group->name = $group_name; |
|---|
| | 191 | $this->creation_root_group = $groups[0]; |
|---|
| | 192 | |
|---|
| | 193 | return true; |
|---|
| | 194 | } |
|---|
| | 195 | else |
|---|
| | 196 | { |
|---|
| | 197 | $this->creation_root_group = new midgard_group(); |
|---|
| | 198 | $this->creation_root_group->owner = $owner_group->id; |
|---|
| | 199 | $this->creation_root_group->sitegroup = $this->sitegroup->id; |
|---|
| | 200 | $this->creation_root_group->name = $group_name; |
|---|
| 180 | | { |
|---|
| 181 | | throw new midgard_admin_sitewizard_exception("Failed to create root group for group structure creation under group GUID: " |
|---|
| 182 | | . $this->creation_root_group->guid); |
|---|
| 183 | | } |
|---|
| 184 | | else |
|---|
| 185 | | { |
|---|
| | 203 | { |
|---|
| | 204 | throw new midgard_admin_sitewizard_exception("Failed to create root group for group |
|---|
| | 205 | structure creation under group GUID: " . $this->creation_root_group->guid); |
|---|
| | 206 | } |
|---|
| | 207 | else |
|---|
| | 208 | { |
|---|
| | 209 | return true; |
|---|
| | 210 | } |
|---|
| | 211 | } |
|---|
| | 212 | } |
|---|
| | 213 | |
|---|
| | 214 | public function create_creation_root_topic($topic_guid, $topic_name = '', $topic_title = '', |
|---|
| | 215 | $component = '', $parameters = array(), $style = '', $create_index = false) |
|---|
| | 216 | { |
|---|
| | 217 | $this->verbose('Creating a root topic for structure creation'); |
|---|
| | 218 | |
|---|
| | 219 | $topic = new midgard_topic($topic_guid); |
|---|
| | 220 | |
|---|
| | 221 | $mc = new midgard_collector('midgard_topic', 'up', $topic->id); |
|---|
| | 222 | $mc->add_constraint('name', '=', $topic_name); |
|---|
| | 223 | $mc->set_key_property('id'); |
|---|
| | 224 | $mc->execute(); |
|---|
| | 225 | $keys = $mc->list_keys(); |
|---|
| | 226 | |
|---|
| | 227 | if (count($keys) > 0) |
|---|
| | 228 | { |
|---|
| | 229 | throw new midgard_admin_sitewizard_exception("Can't create root topic! Reason: name already exists."); |
|---|
| | 230 | } |
|---|
| | 231 | else |
|---|
| | 232 | { |
|---|
| | 233 | $this->creation_root_topic = new midgard_topic(); |
|---|
| | 234 | $this->creation_root_topic->extra = $topic_title; |
|---|
| | 235 | $this->creation_root_topic->name = $topic_name; |
|---|
| | 236 | $this->creation_root_topic->sitegroup = $this->sitegroup->id; |
|---|
| | 237 | $this->creation_root_topic->component = $component; |
|---|
| | 238 | $this->creation_root_topic->up = $topic->id; |
|---|
| | 239 | |
|---|
| | 240 | if (!empty($style)) |
|---|
| | 241 | { |
|---|
| | 242 | $this->verbose("Setting style for topic" . $topic_name . ": (" . $style . ")"); |
|---|
| | 243 | $this->creation_root_topic->style = $style; |
|---|
| | 244 | } |
|---|
| | 245 | |
|---|
| | 246 | if (!$this->creation_root_topic->create()) |
|---|
| | 247 | { |
|---|
| | 248 | throw new midgard_admin_sitewizard_exception("Failed to create root topic for structure creation GUID: " |
|---|
| | 249 | . $this->creation_root_topic->guid . " Reason: " . mdg_errstr()); |
|---|
| | 250 | } |
|---|
| | 251 | else |
|---|
| | 252 | { |
|---|
| | 253 | // Setting style parameter |
|---|
| | 254 | if (!empty($style)) |
|---|
| | 255 | { |
|---|
| | 256 | $this->creation_root_topic->parameter('midcom', 'style', $style); |
|---|
| | 257 | } |
|---|
| | 258 | |
|---|
| | 259 | $this->verbose("Created root topic for structure creation GUID: " . $this->creation_root_topic->guid); |
|---|
| 187 | | return true; |
|---|
| 188 | | } |
|---|
| 189 | | } |
|---|
| 190 | | } |
|---|
| 191 | | |
|---|
| 192 | | public function create_creation_root_topic($topic_guid, $topic_name = "", $topic_title = "", $component = "", $parameters = array()) |
|---|
| 193 | | { |
|---|
| 194 | | $this->verbose('Creating a root topic for structure creation'); |
|---|
| 195 | | |
|---|
| 196 | | $topic = new midgard_topic($topic_guid); |
|---|
| 197 | | |
|---|
| 198 | | $this->creation_root_topic = new midgard_topic(); |
|---|
| 199 | | $this->creation_root_topic->title = $topic_title; |
|---|
| 200 | | $this->creation_root_topic->name = $topic_name; |
|---|
| 201 | | $this->creation_root_topic->sitegroup = $this->sitegroup->id; |
|---|
| 202 | | $this->creation_root_topic->component = $component; |
|---|
| 203 | | $this->creation_root_topic->up = $topic->id; |
|---|
| 204 | | |
|---|
| 205 | | if (!$this->creation_root_topic->create()) |
|---|
| 206 | | { |
|---|
| 207 | | throw new midgard_admin_sitewizard_exception("Failed to create root topic for structure creation GUID: " |
|---|
| 208 | | . $this->creation_root_topic->guid . " Reason: " . mdg_errstr()); |
|---|
| 209 | | } |
|---|
| 210 | | else |
|---|
| 211 | | { |
|---|
| 212 | | $this->verbose("Created root topic for structure creation GUID: " . $this->creation_root_topic->guid); |
|---|
| 213 | | |
|---|
| 214 | | // Setting additional parameters |
|---|
| 215 | | foreach ($parameters as $domain => $parameter) |
|---|
| 216 | | { |
|---|
| 217 | | foreach ($parameter as $name => $value) |
|---|
| 218 | | { |
|---|
| 219 | | $this->creation_root_topic->parameter($domain, $name, $value); |
|---|
| 220 | | } |
|---|
| 221 | | } |
|---|
| 222 | | } |
|---|
| | 261 | // Setting additional parameters |
|---|
| | 262 | foreach ($parameters as $domain => $parameter) |
|---|
| | 263 | { |
|---|
| | 264 | foreach ($parameter as $name => $value) |
|---|
| | 265 | { |
|---|
| | 266 | $this->creation_root_topic->parameter($domain, $name, $value); |
|---|
| | 267 | } |
|---|
| | 268 | } |
|---|
| | 269 | |
|---|
| | 270 | if ($create_index == true) |
|---|
| | 271 | { |
|---|
| | 272 | $this->create_index_article($this->creation_root_topic->id, $topic_title); |
|---|
| | 273 | } |
|---|
| | 274 | } |
|---|
| | 275 | } |
|---|
| 243 | | $topic->title = $this->replace($node['title']); |
|---|
| 244 | | $topic->sitegroup = $this->sitegroup->id; |
|---|
| 245 | | $topic->component = $node['component']; |
|---|
| 246 | | |
|---|
| 247 | | if (!$topic->create()) |
|---|
| 248 | | { |
|---|
| 249 | | throw new midagard_admin_sitewizard_exception("Failed to create topic \"" . $topic->title . "\" under parent GUID: " |
|---|
| 250 | | . $parent_node->guid); |
|---|
| 251 | | } |
|---|
| 252 | | else |
|---|
| 253 | | { |
|---|
| 254 | | // Setting additional parameters |
|---|
| 255 | | if (isset($node['parameters']) && count($node['parameters']) > 0) |
|---|
| | 296 | $topic->extra = $this->replace($node['title']); |
|---|
| | 297 | $topic->sitegroup = $this->sitegroup->id; |
|---|
| | 298 | $topic->component = $node['component']; |
|---|
| | 299 | |
|---|
| | 300 | if (isset($node['style']) && !empty($node['style'])) |
|---|
| | 301 | { |
|---|
| | 302 | $this->verbose("Setting style for topic " . $node['name'] . ": (" . $node['style'] . ")"); |
|---|
| | 303 | $topic->style = $node['style']; |
|---|
| | 304 | } |
|---|
| | 305 | |
|---|
| | 306 | if (!$topic->create()) |
|---|
| | 307 | { |
|---|
| | 308 | throw new midagard_admin_sitewizard_exception("Failed to create topic \"" |
|---|
| | 309 | . $topic->extra . "\" under parent GUID: " . $parent_node->guid); |
|---|
| | 310 | } |
|---|
| | 311 | else |
|---|
| | 312 | { |
|---|
| | 313 | // Setting style parameter |
|---|
| | 314 | if (isset($node['style']) && !empty($node['style'])) |
|---|
| | 315 | { |
|---|
| | 316 | $topic->parameter('midcom', 'style', $node['style']); |
|---|
| | 317 | } |
|---|
| | 318 | |
|---|
| | 319 | // Setting additional parameters |
|---|
| | 320 | if (isset($node['parameters']) && count($node['parameters']) > 0) |
|---|
| 260 | | } |
|---|
| 261 | | |
|---|
| 262 | | // Setting midcom acl privileges |
|---|
| 263 | | if (isset($node['acl']) && count($node['acl']) > 0) |
|---|
| 264 | | { |
|---|
| 265 | | $this->verbose("Starting to set midcom acl privileges for topic GUID: " . $topic->guid); |
|---|
| 266 | | |
|---|
| 267 | | $this->set_privileges($node, $this->creation_root_topic); |
|---|
| 268 | | } |
|---|
| 269 | | } |
|---|
| 270 | | |
|---|
| 271 | | if (isset($node['nodes']) && count($node['nodes']) > 0) |
|---|
| 272 | | { |
|---|
| | 325 | } |
|---|
| | 326 | |
|---|
| | 327 | // Setting midcom acl privileges |
|---|
| | 328 | if (isset($node['acl']) && count($node['acl']) > 0) |
|---|
| | 329 | { |
|---|
| | 330 | $this->verbose("Starting to set midcom acl privileges for topic GUID: " . $topic->guid); |
|---|
| | 331 | |
|---|
| | 332 | $this->set_privileges($node, $this->creation_root_topic); |
|---|
| | 333 | } |
|---|
| | 334 | |
|---|
| | 335 | if (isset($node['create_index']) && $node['create_index'] == true) |
|---|
| | 336 | { |
|---|
| | 337 | $this->create_index_article($topic->id, $this->replace($node['title'])); |
|---|
| | 338 | } |
|---|
| | 339 | } |
|---|
| | 340 | |
|---|
| | 341 | if (isset($node['nodes']) && count($node['nodes']) > 0) |
|---|
| | 342 | { |
|---|
| 338 | | $this->creation_root_topic = midgard_topic(); |
|---|
| 339 | | $this->creation_root_topic->up = 0; |
|---|
| 340 | | $this->creation_root_topic->sitegroup = $this->sitegroup->id; |
|---|
| 341 | | $this->creation_root_topic->title = $this->structure['root']['title']; |
|---|
| 342 | | $this->creation_root_topic->name = $this->structure['root']['name']; |
|---|
| 343 | | |
|---|
| 344 | | if (!$this->creation_root_topic->create()) |
|---|
| 345 | | { |
|---|
| 346 | | throw new midgard_admin_sitewizard_exception("Failed to create root topic \"" . $this->structure['root']['name'] |
|---|
| 347 | | . "\" for structure creation"); |
|---|
| 348 | | |
|---|
| 349 | | return false; |
|---|
| 350 | | } |
|---|
| 351 | | else |
|---|
| 352 | | { |
|---|
| 353 | | // Setting additional parameters |
|---|
| 354 | | if (isset($this->structure['root']['parameters']) && count($this->structure['root']['parameters']) > 0) |
|---|
| 355 | | { |
|---|
| 356 | | $this->set_parameters($this->structure['root'], $this->creation_root_topic); |
|---|
| | 408 | $this->creation_root_topic = midgard_topic(); |
|---|
| | 409 | $this->creation_root_topic->up = 0; |
|---|
| | 410 | $this->creation_root_topic->sitegroup = $this->sitegroup->id; |
|---|
| | 411 | $this->creation_root_topic->extra = $this->structure['root']['title']; |
|---|
| | 412 | $this->creation_root_topic->name = $this->structure['root']['name']; |
|---|
| | 413 | |
|---|
| | 414 | if (isset($node['root']['style']) && !empty($node['root']['style'])) |
|---|
| | 415 | { |
|---|
| | 416 | $this->verbose("Setting style for topic " . $this->structure['root']['name'] |
|---|
| | 417 | . "(" . $node['root']['style'] . ")"); |
|---|
| | 418 | $this->creation_root_topic->style = $node['root']['style']; |
|---|
| | 419 | } |
|---|
| | 420 | |
|---|
| | 421 | if (!$this->creation_root_topic->create()) |
|---|
| | 422 | { |
|---|
| | 423 | throw new midgard_admin_sitewizard_exception("Failed to create root topic \"" |
|---|
| | 424 | . $this->structure['root']['name'] . "\" for structure creation"); |
|---|
| | 425 | |
|---|
| | 426 | return false; |
|---|
| | 427 | } |
|---|
| | 428 | else |
|---|
| | 429 | { |
|---|
| | 430 | // Setting style parameter |
|---|
| | 431 | if (isset($node['root']['style']) && !empty($node['root']['style'])) |
|---|
| | 432 | { |
|---|
| | 433 | $this->creation_root_topic->parameter('midcom', 'style', $node['root']['style']); |
|---|
| | 434 | } |
|---|
| | 435 | |
|---|
| | 436 | // Setting additional parameters |
|---|
| | 437 | if (isset($this->structure['root']['parameters']) && count($this->structure['root']['parameters']) > 0) |
|---|
| | 438 | { |
|---|
| | 439 | $this->set_parameters($this->structure['root'], $this->creation_root_topic); |
|---|
| 368 | | $qb = new midgard_query_builder('midgard_topic'); |
|---|
| 369 | | $qb->add_constraint('up', '=', $this->creation_root_topic->id); |
|---|
| 370 | | $qb->add_constraint('sitegroup', '=', $this->sitegroup->id); |
|---|
| 371 | | $topics = $qb->execute(); |
|---|
| | 456 | $qb = new midgard_query_builder('midgard_topic'); |
|---|
| | 457 | $qb->add_constraint('up', '=', $this->creation_root_topic->id); |
|---|
| | 458 | $qb->add_constraint('sitegroup', '=', $this->sitegroup->id); |
|---|
| | 459 | $topics = $qb->execute(); |
|---|
| 408 | | $qb->add_constraint('sitegroup', '=', $this->sitegroup->id); |
|---|
| 409 | | $qb->add_constraint('owner', '=', $group_owner_id); |
|---|
| 410 | | $groups = $qb->execute(); |
|---|
| 411 | | |
|---|
| 412 | | if (count($groups) != 0) |
|---|
| 413 | | { |
|---|
| 414 | | // Ok, let's first check if a group already exists |
|---|
| 415 | | |
|---|
| 416 | | foreach ($this->config as $structure) |
|---|
| 417 | | { |
|---|
| | 496 | $qb->add_constraint('sitegroup', '=', $this->sitegroup->id); |
|---|
| | 497 | $qb->add_constraint('owner', '=', $group_owner_id); |
|---|
| | 498 | $groups = $qb->execute(); |
|---|
| | 499 | |
|---|
| | 500 | if (count($groups) != 0) |
|---|
| | 501 | { |
|---|
| | 502 | // Ok, let's first check if a group already exists |
|---|
| | 503 | foreach ($this->config as $structure) |
|---|
| | 504 | { |
|---|
| 449 | | . "\" GUID: " . $new_group->guid . " Reason: " . mgd_errstr()); |
|---|
| 450 | | } |
|---|
| 451 | | else |
|---|
| 452 | | { |
|---|
| 453 | | $this->created_groups[$new_group->name] = $new_group; |
|---|
| 454 | | return true; |
|---|
| 455 | | } |
|---|
| 456 | | } |
|---|
| 457 | | } |
|---|
| 458 | | } |
|---|
| 459 | | } |
|---|
| 460 | | else |
|---|
| 461 | | { |
|---|
| 462 | | // There are no groups so we can just create the groups from config file |
|---|
| 463 | | |
|---|
| 464 | | foreach ($this->config as $structure) |
|---|
| 465 | | { |
|---|
| | 537 | . "\" GUID: " . $new_group->guid . " Reason: " . mgd_errstr()); |
|---|
| | 538 | } |
|---|
| | 539 | else |
|---|
| | 540 | { |
|---|
| | 541 | $this->created_groups[$new_group->name] = $new_group; |
|---|
| | 542 | return true; |
|---|
| | 543 | } |
|---|
| | 544 | } |
|---|
| | 545 | } |
|---|
| | 546 | } |
|---|
| | 547 | } |
|---|
| | 548 | else |
|---|
| | 549 | { |
|---|
| | 550 | // There are no groups so we can just create the groups from config file |
|---|
| | 551 | foreach ($this->config as $structure) |
|---|
| | 552 | { |
|---|
| 510 | | { |
|---|
| 511 | | $this->create_group_structure(); |
|---|
| 512 | | $this->create_topic_structure(); |
|---|
| 513 | | |
|---|
| 514 | | $this->verbose("Sitewizard created website structure successfully. Now cleaning up..."); |
|---|
| 515 | | |
|---|
| 516 | | $this->cleanup(); |
|---|
| 517 | | } |
|---|
| 518 | | catch(midgard_admin_sitewizard_exception $e) |
|---|
| 519 | | { |
|---|
| 520 | | $e->error(); |
|---|
| | 597 | { |
|---|
| | 598 | $this->create_group_structure(); |
|---|
| | 599 | $this->create_topic_structure(); |
|---|
| | 600 | |
|---|
| | 601 | $this->verbose("Sitewizard created website structure successfully. Now cleaning up..."); |
|---|
| | 602 | |
|---|
| | 603 | $this->cleanup(); |
|---|
| | 604 | |
|---|
| | 605 | return $this->creation_root_topic->guid; |
|---|
| | 606 | } |
|---|
| | 607 | catch(midgard_admin_sitewizard_exception $e) |
|---|
| | 608 | { |
|---|
| | 609 | $e->error(); |
|---|