PageRenderTime 68ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/concrete/src/Backup/ContentImporter.php

https://gitlab.com/koodersmiikka/operaatio-terveys
PHP | 1045 lines | 974 code | 62 blank | 9 comment | 153 complexity | fc6ce4e85a1155ebed67c44ca3e1611d MD5 | raw file
  1. <?php
  2. namespace Concrete\Core\Backup;
  3. use Concrete\Core\File\Importer;
  4. use Concrete\Core\Page\Feed;
  5. use Concrete\Core\Sharing\SocialNetwork\Link;
  6. use Concrete\Core\Tree\Tree;
  7. use Page;
  8. use Package;
  9. use Stack;
  10. use SinglePage;
  11. use UserInfo;
  12. use PageType;
  13. use BlockType;
  14. use Block;
  15. use Group;
  16. use PageTheme;
  17. use Core;
  18. use Database;
  19. use Job;
  20. use JobSet;
  21. use PageTemplate;
  22. use CollectionAttributeKey;
  23. use Concrete\Core\StyleCustomizer\Inline\StyleSet;
  24. use Concrete\Core\Block\BlockType\Set as BlockTypeSet;
  25. use Concrete\Core\Attribute\Type as AttributeType;
  26. use Concrete\Core\Attribute\Key\Category as AttributeKeyCategory;
  27. use PermissionKeyCategory;
  28. use PermissionKey;
  29. use Concrete\Core\Permission\Access\Entity\Type as PermissionAccessEntityType;
  30. use Concrete\Core\Workflow\Progress\Category as WorkflowProgressCategory;
  31. use Concrete\Core\Permission\Access\Entity\GroupEntity as GroupPermissionAccessEntity;
  32. use PermissionAccess;
  33. use Concrete\Core\Captcha\Library as SystemCaptchaLibrary;
  34. use Concrete\Core\Editor\Snippet as SystemContentEditorSnippet;
  35. use Concrete\Core\Feature\Feature;
  36. use Concrete\Core\Feature\Category\Category as FeatureCategory;
  37. use Concrete\Core\Gathering\DataSource\DataSource as GatheringDataSource;
  38. use Concrete\Core\Gathering\Item\Template\Template as GatheringItemTemplate;
  39. use Concrete\Core\Gathering\Item\Template\Type as GatheringItemTemplateType;
  40. use Concrete\Core\Page\Type\Composer\Control\Type\Type as PageTypeComposerControlType;
  41. use Concrete\Core\Page\Type\PublishTarget\Type\Type as PageTypePublishTargetType;
  42. use Concrete\Core\Conversation\Editor\Editor as ConversationEditor;
  43. use Concrete\Core\Conversation\Rating\Type as ConversationRatingType;
  44. use Concrete\Core\Conversation\FlagType\FlagType as ConversationFlagType;
  45. use Concrete\Core\Validation\BannedWord\BannedWord as BannedWord;
  46. use Concrete\Core\Page\Type\Composer\FormLayoutSetControl as PageTypeComposerFormLayoutSetControl;
  47. class ContentImporter
  48. {
  49. protected static $mcBlockIDs = array();
  50. protected static $ptComposerOutputControlIDs = array();
  51. public function importContentFile($file)
  52. {
  53. $sx = simplexml_load_file($file);
  54. $this->doImport($sx);
  55. }
  56. public function importContentString($string)
  57. {
  58. $sx = simplexml_load_string($string);
  59. $this->doImport($sx);
  60. }
  61. protected function doImport($sx)
  62. {
  63. $this->importSinglePageStructure($sx);
  64. $this->importStacksStructure($sx);
  65. $this->importBlockTypes($sx);
  66. $this->importBlockTypeSets($sx);
  67. $this->importConversationEditors($sx);
  68. $this->importConversationRatingTypes($sx);
  69. $this->importConversationFlagTypes($sx);
  70. $this->importPageTypePublishTargetTypes($sx);
  71. $this->importPageTypeComposerControlTypes($sx);
  72. $this->importBannedWords($sx);
  73. $this->importSocialLinks($sx);
  74. $this->importTrees($sx);
  75. $this->importFileImportantThumbnailTypes($sx);
  76. $this->importFeatures($sx);
  77. $this->importFeatureCategories($sx);
  78. $this->importGatheringDataSources($sx);
  79. $this->importGatheringItemTemplateTypes($sx);
  80. $this->importGatheringItemTemplates($sx);
  81. $this->importAttributeCategories($sx);
  82. $this->importAttributeTypes($sx);
  83. $this->importWorkflowTypes($sx);
  84. $this->importWorkflowProgressCategories($sx);
  85. $this->importAttributes($sx);
  86. $this->importAttributeSets($sx);
  87. $this->importThemes($sx);
  88. $this->importPermissionCategories($sx);
  89. $this->importPermissionAccessEntityTypes($sx);
  90. $this->importTaskPermissions($sx);
  91. $this->importPermissions($sx);
  92. $this->importJobs($sx);
  93. $this->importJobSets($sx);
  94. // import bare page types first, then import structure, then page types blocks, attributes and composer settings, then page content, because we need the structure for certain attributes and stuff set in master collections (like composer)
  95. $this->importPageTemplates($sx);
  96. $this->importPageTypesBase($sx);
  97. $this->importPageStructure($sx);
  98. $this->importPageFeeds($sx);
  99. $this->importPageTypeTargets($sx);
  100. $this->importPageTypeDefaults($sx);
  101. $this->importSinglePageContent($sx);
  102. $this->importStacksContent($sx);
  103. $this->importPageContent($sx);
  104. $this->importPackages($sx);
  105. $this->importConfigValues($sx);
  106. $this->importSystemCaptchaLibraries($sx);
  107. $this->importSystemContentEditorSnippets($sx);
  108. }
  109. protected static function getPackageObject($pkgHandle)
  110. {
  111. $pkg = false;
  112. if ($pkgHandle) {
  113. $pkg = Package::getByHandle($pkgHandle);
  114. }
  115. return $pkg;
  116. }
  117. protected function importStacksStructure(\SimpleXMLElement $sx)
  118. {
  119. if (isset($sx->stacks)) {
  120. foreach ($sx->stacks->stack as $p) {
  121. if (isset($p['type'])) {
  122. $type = Stack::mapImportTextToType($p['type']);
  123. Stack::addStack($p['name'], $type);
  124. } else {
  125. Stack::addStack($p['name']);
  126. }
  127. }
  128. }
  129. }
  130. protected function importStacksContent(\SimpleXMLElement $sx)
  131. {
  132. if (isset($sx->stacks)) {
  133. foreach ($sx->stacks->stack as $p) {
  134. $stack = Stack::getByName($p['name']);
  135. if (isset($p->area)) {
  136. $this->importPageAreas($stack, $p);
  137. }
  138. }
  139. }
  140. }
  141. protected function importSinglePageStructure(\SimpleXMLElement $sx)
  142. {
  143. if (isset($sx->singlepages)) {
  144. foreach ($sx->singlepages->page as $p) {
  145. $pkg = static::getPackageObject($p['package']);
  146. $spl = SinglePage::add($p['path'], $pkg);
  147. if (is_object($spl)) {
  148. if (isset($p['root']) && $p['root'] == true) {
  149. $spl->moveToRoot();
  150. }
  151. if ($p['name']) {
  152. $spl->update(array('cName' => $p['name'], 'cDescription' => $p['description']));
  153. }
  154. }
  155. }
  156. }
  157. }
  158. protected function importSinglePageContent(\SimpleXMLElement $sx)
  159. {
  160. if (isset($sx->singlepages)) {
  161. foreach ($sx->singlepages->page as $px) {
  162. $page = Page::getByPath($px['path'], 'RECENT');
  163. if (isset($px->area)) {
  164. $this->importPageAreas($page, $px);
  165. }
  166. if (isset($px->attributes)) {
  167. foreach ($px->attributes->children() as $attr) {
  168. $ak = CollectionAttributeKey::getByHandle($attr['handle']);
  169. if (is_object($ak)) {
  170. $page->setAttribute((string) $attr['handle'], $ak->getController()->importValue($attr));
  171. }
  172. }
  173. }
  174. }
  175. }
  176. }
  177. public function setupPageNodeOrder($pageNodeA, $pageNodeB)
  178. {
  179. $pathA = (string) $pageNodeA['path'];
  180. $pathB = (string) $pageNodeB['path'];
  181. $numA = count(explode('/', $pathA));
  182. $numB = count(explode('/', $pathB));
  183. if ($numA == $numB) {
  184. if (intval($pageNodeA->originalPos) < intval($pageNodeB->originalPos)) {
  185. return -1;
  186. } else {
  187. if (intval($pageNodeA->originalPos) > intval($pageNodeB->originalPos)) {
  188. return 1;
  189. } else {
  190. return 0;
  191. }
  192. }
  193. } else {
  194. return ($numA < $numB) ? -1 : 1;
  195. }
  196. }
  197. protected function importPageContent(\SimpleXMLElement $sx)
  198. {
  199. if (isset($sx->pages)) {
  200. foreach ($sx->pages->page as $px) {
  201. if ($px['path'] != '') {
  202. $page = Page::getByPath($px['path'], 'RECENT');
  203. } else {
  204. $page = Page::getByID(HOME_CID, 'RECENT');
  205. }
  206. if (isset($px->area)) {
  207. $this->importPageAreas($page, $px);
  208. }
  209. if (isset($px->attributes)) {
  210. foreach ($px->attributes->children() as $attr) {
  211. $ak = CollectionAttributeKey::getByHandle($attr['handle']);
  212. if (is_object($ak)) {
  213. $page->setAttribute((string) $attr['handle'], $ak->getController()->importValue($attr));
  214. }
  215. }
  216. }
  217. $page->reindex();
  218. }
  219. }
  220. }
  221. protected function importPageStructure(\SimpleXMLElement $sx)
  222. {
  223. if (isset($sx->pages)) {
  224. $nodes = array();
  225. $i = 0;
  226. foreach ($sx->pages->page as $p) {
  227. $p->originalPos = $i;
  228. $nodes[] = $p;
  229. $i++;
  230. }
  231. usort($nodes, array('static', 'setupPageNodeOrder'));
  232. $home = Page::getByID(HOME_CID, 'RECENT');
  233. foreach ($nodes as $px) {
  234. $pkg = static::getPackageObject($px['package']);
  235. $data = array();
  236. $user = (string) $px['user'];
  237. if ($user != '') {
  238. $ui = UserInfo::getByUserName($user);
  239. if (is_object($ui)) {
  240. $data['uID'] = $ui->getUserID();
  241. } else {
  242. $data['uID'] = USER_SUPER_ID;
  243. }
  244. }
  245. $cDatePublic = (string) $px['public-date'];
  246. if ($cDatePublic) {
  247. $data['cDatePublic'] = $cDatePublic;
  248. }
  249. $data['pkgID'] = 0;
  250. if (is_object($pkg)) {
  251. $data['pkgID'] = $pkg->getPackageID();
  252. }
  253. $args = array();
  254. $ct = PageType::getByHandle($px['pagetype']);
  255. $template = PageTemplate::getByHandle($px['template']);
  256. if ($px['path'] != '') {
  257. // not home page
  258. $page = Page::getByPath($px['path']);
  259. if (!is_object($page) || ($page->isError())) {
  260. $lastSlash = strrpos((string) $px['path'], '/');
  261. $parentPath = substr((string) $px['path'], 0, $lastSlash);
  262. $data['cHandle'] = substr((string) $px['path'], $lastSlash + 1);
  263. if (!$parentPath) {
  264. $parent = $home;
  265. } else {
  266. $parent = Page::getByPath($parentPath);
  267. }
  268. $page = $parent->add($ct, $data);
  269. }
  270. } else {
  271. $page = $home;
  272. }
  273. $args['cName'] = $px['name'];
  274. $args['cDescription'] = $px['description'];
  275. if (is_object($ct)) {
  276. $args['ptID'] = $ct->getPageTypeID();
  277. }
  278. $args['pTemplateID'] = $template->getPageTemplateID();
  279. $page->update($args);
  280. }
  281. }
  282. }
  283. public function importPageAreas(Page $page, \SimpleXMLElement $px)
  284. {
  285. foreach ($px->area as $ax) {
  286. if (isset($ax->blocks)) {
  287. foreach ($ax->blocks->block as $bx) {
  288. if ($bx['type'] != '') {
  289. // we check this because you might just get a block node with only an mc-block-id, if it's an alias
  290. $bt = BlockType::getByHandle((string) $bx['type']);
  291. if (!is_object($bt)) {
  292. throw new \Exception(t('Invalid block type handle: %s', strval($bx['type'])));
  293. }
  294. $btc = $bt->getController();
  295. $btc->import($page, (string) $ax['name'], $bx);
  296. } else {
  297. if ($bx['mc-block-id'] != '') {
  298. // we find that block in the master collection block pool and alias it out
  299. $bID = array_search((string) $bx['mc-block-id'], self::$mcBlockIDs);
  300. if ($bID) {
  301. $mc = Page::getByID($page->getMasterCollectionID(), 'RECENT');
  302. $block = Block::getByID($bID, $mc, (string) $ax['name']);
  303. $block->alias($page);
  304. if ($block->getBlockTypeHandle() == BLOCK_HANDLE_LAYOUT_PROXY) {
  305. // we have to go get the blocks on that page in this layout.
  306. $btc = $block->getController();
  307. $arLayout = $btc->getAreaLayoutObject();
  308. $columns = $arLayout->getAreaLayoutColumns();
  309. foreach ($columns as $column) {
  310. $area = $column->getAreaObject();
  311. $blocks = $area->getAreaBlocksArray($mc);
  312. foreach ($blocks as $_b) {
  313. $_b->alias($page);
  314. }
  315. }
  316. }
  317. }
  318. }
  319. }
  320. }
  321. }
  322. if (isset($ax->style)) {
  323. $area = \Area::get($page, (string) $ax['name']);
  324. $set = StyleSet::import($ax->style);
  325. $page->setCustomStyleSet($area, $set);
  326. }
  327. }
  328. }
  329. public static function addMasterCollectionBlockID($b, $id)
  330. {
  331. self::$mcBlockIDs[$b->getBlockID()] = $id;
  332. }
  333. public static function getMasterCollectionTemporaryBlockID($b)
  334. {
  335. if (isset(self::$mcBlockIDs[$b->getBlockID()])) {
  336. return self::$mcBlockIDs[$b->getBlockID()];
  337. }
  338. }
  339. public static function addPageTypeComposerOutputControlID(PageTypeComposerFormLayoutSetControl $control, $id)
  340. {
  341. self::$ptComposerOutputControlIDs[$id] = $control->getPageTypeComposerFormLayoutSetControlID();
  342. }
  343. public static function getPageTypeComposerFormLayoutSetControlFromTemporaryID($id)
  344. {
  345. if (isset(self::$ptComposerOutputControlIDs[$id])) {
  346. return self::$ptComposerOutputControlIDs[$id];
  347. }
  348. }
  349. protected function importPageTemplates(\SimpleXMLElement $sx)
  350. {
  351. if (isset($sx->pagetemplates)) {
  352. foreach ($sx->pagetemplates->pagetemplate as $pt) {
  353. $pkg = static::getPackageObject($pt['package']);
  354. $ptt = PageTemplate::getByHandle($pt['handle']);
  355. if (!is_object($ptt)) {
  356. $ptt = PageTemplate::add(
  357. (string) $pt['handle'],
  358. (string) $pt['name'],
  359. (string) $pt['icon'],
  360. $pkg,
  361. (string) $pt['internal']
  362. );
  363. }
  364. }
  365. }
  366. }
  367. protected function importBlockTypes(\SimpleXMLElement $sx)
  368. {
  369. if (isset($sx->blocktypes)) {
  370. foreach ($sx->blocktypes->blocktype as $bt) {
  371. if (!is_object(BlockType::getByHandle((string) $bt['handle']))) {
  372. $pkg = static::getPackageObject($bt['package']);
  373. if (is_object($pkg)) {
  374. BlockType::installBlockTypeFromPackage((string) $bt['handle'], $pkg);
  375. } else {
  376. BlockType::installBlockType((string) $bt['handle']);
  377. }
  378. }
  379. }
  380. }
  381. }
  382. protected function importWorkflowTypes(\SimpleXMLElement $sx)
  383. {
  384. if (isset($sx->workflowtypes)) {
  385. foreach ($sx->workflowtypes->workflowtype as $wt) {
  386. $pkg = static::getPackageObject($wt['package']);
  387. $name = $wt['name'];
  388. if (!$name) {
  389. $name = Core::make('helper/text')->unhandle($wt['handle']);
  390. }
  391. $type = \Concrete\Core\Workflow\Type::add($wt['handle'], $name, $pkg);
  392. }
  393. }
  394. }
  395. protected function importAttributeTypes(\SimpleXMLElement $sx)
  396. {
  397. if (isset($sx->attributetypes)) {
  398. foreach ($sx->attributetypes->attributetype as $at) {
  399. $pkg = static::getPackageObject($at['package']);
  400. $name = $at['name'];
  401. if (!$name) {
  402. $name = Core::make('helper/text')->unhandle($at['handle']);
  403. }
  404. $type = AttributeType::getByHandle($at['handle']);
  405. if (!is_object($type)) {
  406. $type = AttributeType::add($at['handle'], $name, $pkg);
  407. }
  408. if (isset($at->categories)) {
  409. foreach ($at->categories->children() as $cat) {
  410. $catobj = AttributeKeyCategory::getByHandle((string) $cat['handle']);
  411. $catobj->associateAttributeKeyType($type);
  412. }
  413. }
  414. }
  415. }
  416. }
  417. protected function importPermissionAccessEntityTypes(\SimpleXMLElement $sx)
  418. {
  419. if (isset($sx->permissionaccessentitytypes)) {
  420. foreach ($sx->permissionaccessentitytypes->permissionaccessentitytype as $pt) {
  421. $type = PermissionAccessEntityType::getByHandle((string) $pt['handle']);
  422. if (!is_object($type)) {
  423. $pkg = static::getPackageObject($pt['package']);
  424. $name = $pt['name'];
  425. if (!$name) {
  426. $name = Core::make('helper/text')->unhandle($pt['handle']);
  427. }
  428. $type = PermissionAccessEntityType::add($pt['handle'], $name, $pkg);
  429. }
  430. if (isset($pt->categories)) {
  431. foreach ($pt->categories->children() as $cat) {
  432. $catobj = PermissionKeyCategory::getByHandle((string) $cat['handle']);
  433. $catobj->associateAccessEntityType($type);
  434. }
  435. }
  436. }
  437. }
  438. }
  439. protected function importPackages(\SimpleXMLElement $sx)
  440. {
  441. if (isset($sx->packages)) {
  442. foreach ($sx->packages->package as $p) {
  443. $pkg = Package::getClass((string) $p['handle']);
  444. if (!$pkg->isPackageInstalled()) {
  445. $pkg->install();
  446. }
  447. }
  448. }
  449. }
  450. protected function importThemes(\SimpleXMLElement $sx)
  451. {
  452. if (isset($sx->themes)) {
  453. foreach ($sx->themes->theme as $th) {
  454. $pkg = static::getPackageObject($th['package']);
  455. $pThemeHandle = (string) $th['handle'];
  456. $pt = PageTheme::getByHandle($pThemeHandle);
  457. if (!is_object($pt)) {
  458. $pt = PageTheme::add($pThemeHandle, $pkg);
  459. }
  460. if ($th['activated'] == '1') {
  461. $pt->applyToSite();
  462. }
  463. }
  464. }
  465. }
  466. protected function importPageTypePublishTargetTypes(\SimpleXMLElement $sx)
  467. {
  468. if (isset($sx->pagetypepublishtargettypes)) {
  469. foreach ($sx->pagetypepublishtargettypes->type as $th) {
  470. $pkg = static::getPackageObject($th['package']);
  471. $ce = PageTypePublishTargetType::add((string) $th['handle'], (string) $th['name'], $pkg);
  472. }
  473. }
  474. }
  475. protected function importPageTypeComposerControlTypes(\SimpleXMLElement $sx)
  476. {
  477. if (isset($sx->pagetypecomposercontroltypes)) {
  478. foreach ($sx->pagetypecomposercontroltypes->type as $th) {
  479. $pkg = static::getPackageObject($th['package']);
  480. $ce = PageTypeComposerControlType::add((string) $th['handle'], (string) $th['name'], $pkg);
  481. }
  482. }
  483. }
  484. protected function importPageTypesBase(\SimpleXMLElement $sx)
  485. {
  486. if (isset($sx->pagetypes)) {
  487. foreach ($sx->pagetypes->pagetype as $p) {
  488. PageType::import($p);
  489. }
  490. }
  491. }
  492. protected function importPageTypeTargets(\SimpleXMLElement $sx)
  493. {
  494. if (isset($sx->pagetypes)) {
  495. foreach ($sx->pagetypes->pagetype as $p) {
  496. PageType::importTargets($p);
  497. }
  498. }
  499. }
  500. protected function importPageTypeDefaults(\SimpleXMLElement $sx)
  501. {
  502. if (isset($sx->pagetypes)) {
  503. foreach ($sx->pagetypes->pagetype as $p) {
  504. PageType::importContent($p);
  505. }
  506. }
  507. }
  508. protected function importConversationEditors(\SimpleXMLElement $sx)
  509. {
  510. if (isset($sx->conversationeditors)) {
  511. foreach ($sx->conversationeditors->editor as $th) {
  512. $pkg = static::getPackageObject($th['package']);
  513. $ce = ConversationEditor::add((string) $th['handle'], (string) $th['name'], $pkg);
  514. if ($th['activated'] == '1') {
  515. $ce->activate();
  516. }
  517. }
  518. }
  519. }
  520. protected function importConversationRatingTypes(\SimpleXMLElement $sx)
  521. {
  522. if (isset($sx->conversationratingtypes)) {
  523. foreach ($sx->conversationratingtypes->conversationratingtype as $th) {
  524. $pkg = static::getPackageObject($th['package']);
  525. $ce = ConversationRatingType::add((string) $th['handle'], (string) $th['name'], $th['points'], $pkg);
  526. }
  527. }
  528. }
  529. protected function importBannedWords(\SimpleXMLElement $sx)
  530. {
  531. if (isset($sx->banned_words)) {
  532. foreach ($sx->banned_words->banned_word as $p) {
  533. $bw = BannedWord::add(str_rot13($p));
  534. }
  535. }
  536. }
  537. protected function importSocialLinks(\SimpleXMLElement $sx)
  538. {
  539. if (isset($sx->sociallinks)) {
  540. foreach ($sx->sociallinks->link as $l) {
  541. $sociallink = Link::getByServiceHandle((string) $l['service']);
  542. if (!is_object($sociallink)) {
  543. $sociallink = new Link();
  544. $sociallink->setURL((string) $l['url']);
  545. $sociallink->setServiceHandle((string) $l['service']);
  546. $sociallink->save();
  547. }
  548. }
  549. }
  550. }
  551. protected function importPageFeeds(\SimpleXMLElement $sx)
  552. {
  553. if (isset($sx->pagefeeds)) {
  554. foreach ($sx->pagefeeds->feed as $f) {
  555. $feed = Feed::getByHandle((string) $f->handle);
  556. $inspector = \Core::make('import/value_inspector');
  557. if (!is_object($feed)) {
  558. $feed = new Feed();
  559. }
  560. if ($f->parent) {
  561. $result = $inspector->inspect((string) $f->parent);
  562. $parent = $result->getReplacedValue();
  563. $feed->setParentID($parent);
  564. }
  565. $feed->setTitle((string) $f->title);
  566. $feed->setDescription((string) $f->description);
  567. $feed->setHandle((string) $f->handle);
  568. if ($f->descendents) {
  569. $feed->setIncludeAllDescendents(true);
  570. }
  571. if ($f->aliases) {
  572. $feed->setDisplayAliases(true);
  573. }
  574. if ($f->featured) {
  575. $feed->setDisplayFeaturedOnly(true);
  576. }
  577. if ($f->pagetype) {
  578. $result = $inspector->inspect((string) $f->pagetype);
  579. $pagetype = $result->getReplacedValue();
  580. $feed->setPageTypeID($pagetype);
  581. }
  582. $contentType = $f->contenttype;
  583. $type = (string) $contentType['type'];
  584. if ($type == 'description') {
  585. $feed->displayShortDescriptionContent();
  586. } elseif ($type == 'area') {
  587. $feed->displayAreaContent((string) $contentType['handle']);
  588. }
  589. $feed->save();
  590. }
  591. }
  592. }
  593. protected function importTrees(\SimpleXMLElement $sx)
  594. {
  595. if (isset($sx->trees)) {
  596. foreach ($sx->trees->tree as $t) {
  597. Tree::import($t);
  598. }
  599. }
  600. }
  601. protected function importFileImportantThumbnailTypes(\SimpleXMLElement $sx)
  602. {
  603. if (isset($sx->thumbnailtypes)) {
  604. foreach ($sx->thumbnailtypes->thumbnailtype as $l) {
  605. $type = new \Concrete\Core\File\Image\Thumbnail\Type\Type();
  606. $type->setName((string) $l['name']);
  607. $type->setHandle((string) $l['handle']);
  608. $type->setWidth((string) $l['width']);
  609. $type->setHeight((string) $l['height']);
  610. $required = (string) $l['required'];
  611. if ($required) {
  612. $type->requireType();
  613. }
  614. $type->save();
  615. }
  616. }
  617. }
  618. protected function importConversationFlagTypes(\SimpleXMLElement $sx)
  619. {
  620. if (isset($sx->flag_types)) {
  621. foreach ($sx->flag_types->flag_type as $p) {
  622. $bw = ConversationFlagType::add((string) $p);
  623. }
  624. }
  625. }
  626. protected function importSystemCaptchaLibraries(\SimpleXMLElement $sx)
  627. {
  628. if (isset($sx->systemcaptcha)) {
  629. foreach ($sx->systemcaptcha->library as $th) {
  630. $pkg = static::getPackageObject($th['package']);
  631. $scl = SystemCaptchaLibrary::add($th['handle'], $th['name'], $pkg);
  632. if ($th['activated'] == '1') {
  633. $scl->activate();
  634. }
  635. }
  636. }
  637. }
  638. protected function importSystemContentEditorSnippets(\SimpleXMLElement $sx)
  639. {
  640. if (isset($sx->systemcontenteditorsnippets)) {
  641. foreach ($sx->systemcontenteditorsnippets->snippet as $th) {
  642. $pkg = static::getPackageObject($th['package']);
  643. $scs = SystemContentEditorSnippet::add($th['handle'], $th['name'], $pkg);
  644. if ($th['activated'] == '1') {
  645. $scs->activate();
  646. }
  647. }
  648. }
  649. }
  650. protected function importJobs(\SimpleXMLElement $sx)
  651. {
  652. if (isset($sx->jobs)) {
  653. foreach ($sx->jobs->job as $jx) {
  654. $pkg = static::getPackageObject($jx['package']);
  655. $job = Job::getByHandle($jx['handle']);
  656. if (!is_object($job)) {
  657. if (is_object($pkg)) {
  658. Job::installByPackage($jx['handle'], $pkg);
  659. } else {
  660. Job::installByHandle($jx['handle']);
  661. }
  662. }
  663. }
  664. }
  665. }
  666. protected function importJobSets(\SimpleXMLElement $sx)
  667. {
  668. if (isset($sx->jobsets)) {
  669. foreach ($sx->jobsets->jobset as $js) {
  670. $jso = JobSet::getByName((string) $js['name']);
  671. if (!is_object($jso)) {
  672. $pkg = static::getPackageObject($js['package']);
  673. if (is_object($pkg)) {
  674. $jso = JobSet::add((string) $js['name'], $pkg);
  675. } else {
  676. $jso = JobSet::add((string) $js['name']);
  677. }
  678. }
  679. foreach ($js->children() as $jsk) {
  680. $j = Job::getByHandle((string) $jsk['handle']);
  681. if (is_object($j)) {
  682. $jso->addJob($j);
  683. }
  684. }
  685. }
  686. }
  687. }
  688. protected function importConfigValues(\SimpleXMLElement $sx)
  689. {
  690. if (isset($sx->config)) {
  691. foreach ($sx->config->children() as $key) {
  692. $pkg = static::getPackageObject($key['package']);
  693. if (is_object($pkg)) {
  694. \Config::save($pkg->getPackageHandle() . '::' . $key->getName(), (string) $key);
  695. } else {
  696. \Config::save($key->getName(), (string) $key);
  697. }
  698. }
  699. }
  700. }
  701. protected function importDatabaseConfigValues(\SimpleXMLElement $sx)
  702. {
  703. if (isset($sx->databaseconfig)) {
  704. $config = Core::make('config/database');
  705. foreach ($sx->databaseconfig->children() as $key) {
  706. $pkg = static::getPackageObject($key['package']);
  707. if (is_object($pkg)) {
  708. $config->save($pkg->getPackageHandle() . '::' . $key->getName(), (string) $key);
  709. } else {
  710. $config->save($key->getName(), (string) $key);
  711. }
  712. }
  713. }
  714. }
  715. protected function importTaskPermissions(\SimpleXMLElement $sx)
  716. {
  717. if (isset($sx->taskpermissions)) {
  718. foreach ($sx->taskpermissions->taskpermission as $tp) {
  719. $pkg = static::getPackageObject($tp['package']);
  720. $tpa = TaskPermission::addTask($tp['handle'], $tp['name'], $tp['description'], $pkg);
  721. if (isset($tp->access)) {
  722. foreach ($tp->access->children() as $ch) {
  723. if ($ch->getName() == 'group') {
  724. $g = Group::getByName($ch['name']);
  725. if (!is_object($g)) {
  726. $g = Group::add($ch['name'], $ch['description']);
  727. }
  728. $tpa->addAccess($g);
  729. }
  730. }
  731. }
  732. }
  733. }
  734. }
  735. protected function importPermissionCategories(\SimpleXMLElement $sx)
  736. {
  737. if (isset($sx->permissioncategories)) {
  738. foreach ($sx->permissioncategories->category as $pkc) {
  739. $pkg = static::getPackageObject($pkc['package']);
  740. $category = PermissionKeyCategory::getByHandle((string) $pkc['handle']);
  741. if (!is_object($category)) {
  742. PermissionKeyCategory::add((string) $pkc['handle'], $pkg);
  743. }
  744. }
  745. }
  746. }
  747. protected function importWorkflowProgressCategories(\SimpleXMLElement $sx)
  748. {
  749. if (isset($sx->workflowprogresscategories)) {
  750. foreach ($sx->workflowprogresscategories->category as $wpc) {
  751. $pkg = static::getPackageObject($wpc['package']);
  752. WorkflowProgressCategory::add((string) $wpc['handle'], $pkg);
  753. }
  754. }
  755. }
  756. protected function importPermissions(\SimpleXMLElement $sx)
  757. {
  758. if (isset($sx->permissionkeys)) {
  759. foreach ($sx->permissionkeys->permissionkey as $pk) {
  760. if (is_object(PermissionKey::getByHandle((string) $pk['handle']))) {
  761. continue;
  762. }
  763. $pkc = PermissionKeyCategory::getByHandle((string) $pk['category']);
  764. $c1 = $pkc->getPermissionKeyClass();
  765. $pkx = call_user_func(array($c1, 'import'), $pk);
  766. $assignments = array();
  767. if (isset($pk->access)) {
  768. foreach ($pk->access->children() as $ch) {
  769. if ($ch->getName() == 'group') {
  770. /*
  771. * Legacy
  772. */
  773. $g = Group::getByName($ch['name']);
  774. if (!is_object($g)) {
  775. $g = Group::add($g['name'], $g['description']);
  776. }
  777. $pae = GroupPermissionAccessEntity::getOrCreate($g);
  778. $assignments[] = $pae;
  779. }
  780. if ($ch->getName() == 'entity') {
  781. $type = PermissionAccessEntityType::getByHandle((string) $ch['type']);
  782. $class = $type->getAccessEntityTypeClass();
  783. if (method_exists($class, 'configureFromImport')) {
  784. $pae = $class::configureFromImport($ch);
  785. $assignments[] = $pae;
  786. }
  787. }
  788. }
  789. }
  790. if (count($assignments)) {
  791. $pa = PermissionAccess::create($pkx);
  792. foreach($assignments as $pae) {
  793. $pa->addListItem($pae);
  794. }
  795. $pt = $pkx->getPermissionAssignmentObject();
  796. $pt->assignPermissionAccess($pa);
  797. }
  798. }
  799. }
  800. }
  801. protected function importFeatures(\SimpleXMLElement $sx)
  802. {
  803. if (isset($sx->features)) {
  804. foreach ($sx->features->feature as $fea) {
  805. $feHasCustomClass = false;
  806. if ($fea['has-custom-class']) {
  807. $feHasCustomClass = true;
  808. }
  809. $pkg = static::getPackageObject($fea['package']);
  810. $fx = Feature::add((string) $fea['handle'], (string) $fea['score'], $feHasCustomClass, $pkg);
  811. }
  812. }
  813. }
  814. protected function importFeatureCategories(\SimpleXMLElement $sx)
  815. {
  816. if (isset($sx->featurecategories)) {
  817. foreach ($sx->featurecategories->featurecategory as $fea) {
  818. $pkg = static::getPackageObject($fea['package']);
  819. $fx = FeatureCategory::add($fea['handle'], $pkg);
  820. }
  821. }
  822. }
  823. protected function importAttributeCategories(\SimpleXMLElement $sx)
  824. {
  825. if (isset($sx->attributecategories)) {
  826. foreach ($sx->attributecategories->category as $akc) {
  827. $pkg = static::getPackageObject($akc['package']);
  828. $akx = AttributeKeyCategory::getByHandle($akc['handle']);
  829. if (!is_object($akx)) {
  830. $akx = AttributeKeyCategory::add($akc['handle'], $akc['allow-sets'], $pkg);
  831. }
  832. }
  833. }
  834. }
  835. protected function importAttributes(\SimpleXMLElement $sx)
  836. {
  837. $db = Database::connection();
  838. if (isset($sx->attributekeys)) {
  839. foreach ($sx->attributekeys->attributekey as $ak) {
  840. $akc = AttributeKeyCategory::getByHandle($ak['category']);
  841. $akID = $db->GetOne('select akID from AttributeKeys where akHandle = ? and akCategoryID = ?', array($ak['handle'], $akc->getAttributeKeyCategoryID()));
  842. if (!$akID) {
  843. $txt = Core::make('helper/text');
  844. $c1 = overrideable_core_class('\\Core\\Attribute\\Key\\' . $txt->camelcase(
  845. $akc->getAttributeKeyCategoryHandle()
  846. ) . 'Key', DIRNAME_CLASSES . '/Attribute/Key/' . $txt->camelcase(
  847. $akc->getAttributeKeyCategoryHandle()
  848. ) . 'Key.php', (string) $akc->getPackageHandle()
  849. );
  850. call_user_func(array($c1, 'import'), $ak);
  851. }
  852. }
  853. }
  854. }
  855. protected function importAttributeSets(\SimpleXMLElement $sx)
  856. {
  857. if (isset($sx->attributesets)) {
  858. foreach ($sx->attributesets->attributeset as $as) {
  859. $set = \Concrete\Core\Attribute\Set::getByHandle((string) $as['handle']);
  860. $akc = AttributeKeyCategory::getByHandle($as['category']);
  861. if (!is_object($set)) {
  862. $pkg = static::getPackageObject($as['package']);
  863. $set = $akc->addSet((string) $as['handle'], (string) $as['name'], $pkg, $as['locked']);
  864. }
  865. foreach ($as->children() as $ask) {
  866. $ak = $akc->getAttributeKeyByHandle((string) $ask['handle']);
  867. if (is_object($ak)) {
  868. $set->addKey($ak);
  869. }
  870. }
  871. }
  872. }
  873. }
  874. protected function importGatheringDataSources(\SimpleXMLElement $sx)
  875. {
  876. if (isset($sx->gatheringsources)) {
  877. foreach ($sx->gatheringsources->gatheringsource as $ags) {
  878. $pkg = static::getPackageObject($ags['package']);
  879. $source = GatheringDataSource::add((string) $ags['handle'], (string) $ags['name'], $pkg);
  880. }
  881. }
  882. }
  883. protected function importGatheringItemTemplateTypes(\SimpleXMLElement $sx)
  884. {
  885. if (isset($sx->gatheringitemtemplatetypes)) {
  886. foreach ($sx->gatheringitemtemplatetypes->gatheringitemtemplatetype as $at) {
  887. $pkg = static::getPackageObject($at['package']);
  888. GatheringItemTemplateType::add((string) $at['handle'], $pkg);
  889. }
  890. }
  891. }
  892. protected function importGatheringItemTemplates(\SimpleXMLElement $sx)
  893. {
  894. if (isset($sx->gatheringitemtemplates)) {
  895. foreach ($sx->gatheringitemtemplates->gatheringitemtemplate as $at) {
  896. $pkg = static::getPackageObject($at['package']);
  897. $type = GatheringItemTemplateType::getByHandle((string) $at['type']);
  898. $gatHasCustomClass = false;
  899. $gatForceDefault = false;
  900. $gatFixedSlotWidth = 0;
  901. $gatFixedSlotHeight = 0;
  902. if ($at['has-custom-class']) {
  903. $gatHasCustomClass = true;
  904. }
  905. if ($at['force-default']) {
  906. $gatForceDefault = true;
  907. }
  908. if ($at['fixed-slot-width']) {
  909. $gatFixedSlotWidth = (string) $at['fixed-slot-width'];
  910. }
  911. if ($at['fixed-slot-height']) {
  912. $gatFixedSlotHeight = (string) $at['fixed-slot-height'];
  913. }
  914. $template = GatheringItemTemplate::add(
  915. $type,
  916. (string) $at['handle'],
  917. (string) $at['name'],
  918. $gatFixedSlotWidth,
  919. $gatFixedSlotHeight,
  920. $gatHasCustomClass,
  921. $gatForceDefault,
  922. $pkg
  923. );
  924. foreach ($at->children() as $fe) {
  925. $feo = Feature::getByHandle((string) $fe['handle']);
  926. if (is_object($feo)) {
  927. $template->addGatheringItemTemplateFeature($feo);
  928. }
  929. }
  930. }
  931. }
  932. }
  933. protected function importBlockTypeSets(\SimpleXMLElement $sx)
  934. {
  935. if (isset($sx->blocktypesets)) {
  936. foreach ($sx->blocktypesets->blocktypeset as $bts) {
  937. $pkg = static::getPackageObject($bts['package']);
  938. $set = BlockTypeSet::getByHandle((string) $bts['handle']);
  939. if (!is_object($set)) {
  940. $set = BlockTypeSet::add((string) $bts['handle'], (string) $bts['name'], $pkg);
  941. }
  942. foreach ($bts->children() as $btk) {
  943. $bt = BlockType::getByHandle((string) $btk['handle']);
  944. if (is_object($bt)) {
  945. $set->addBlockType($bt);
  946. }
  947. }
  948. }
  949. }
  950. }
  951. public function importFiles($fromPath, $computeThumbnails = true)
  952. {
  953. $fh = new Importer();
  954. if (!$computeThumbnails) {
  955. $fh->setRescanThumbnailsOnImport(false);
  956. $helper = Core::make('helper/file');
  957. }
  958. $contents = Core::make('helper/file')->getDirectoryContents($fromPath);
  959. foreach ($contents as $filename) {
  960. if (!is_dir($filename)) {
  961. $fv = $fh->import($fromPath . '/' . $filename, $filename);
  962. if (!$computeThumbnails) {
  963. $types = \Concrete\Core\File\Image\Thumbnail\Type\Type::getVersionList();
  964. foreach ($types as $type) {
  965. // since we provide the thumbnails, we're going to get a list of thumbnail types
  966. // and loop through them, assigning them to all the files.
  967. $thumbnailPath = $fromPath . '/' . $type->getHandle() . '/' . $filename;
  968. if (file_exists($thumbnailPath)) {
  969. $fv->importThumbnail($type, $thumbnailPath);
  970. }
  971. }
  972. }
  973. }
  974. }
  975. }
  976. }