Skip to content

Instantly share code, notes, and snippets.

@ilyautkin
Forked from vgrish/resolve.resources.php
Created June 3, 2016 08:34
Show Gist options
  • Save ilyautkin/34c1dd5944b90d98026dd1854b56ec71 to your computer and use it in GitHub Desktop.
Save ilyautkin/34c1dd5944b90d98026dd1854b56ec71 to your computer and use it in GitHub Desktop.
<?php
/** @var $modx modX */
if (!$modx = $object->xpdo AND !$object->xpdo instanceof modX) {
return true;
}
/** @var $options */
switch ($options[xPDOTransport::PACKAGE_ACTION]) {
case xPDOTransport::ACTION_INSTALL:
case xPDOTransport::ACTION_UPGRADE:
$resources = array(
'404' => array(
'pagetitle' => '404.',
'description' => '',
'template' => 'stoneBase',
'class_key' => 'modDocument',
'published' => 1,
'hidemenu' => 1,
'richtext' => 1,
'parent' => 'service',
'menuindex' => 9999999,
),
'sitemap' => array(
'pagetitle' => 'sitemap',
'description' => '',
'template' => '0',
'class_key' => 'modDocument',
'published' => 1,
'hidemenu' => 1,
'richtext' => 0,
'parent' => 'service',
'menuindex' => 9999999,
'content' => '[[GoogleSiteMap?]]',
'searchable' => 0,
'content_type' => 2,
'contentType' => 'text/xml',
),
'feedback' => array(
'pagetitle' => 'Форма обратной связи',
'description' => '',
'template' => 'stoneBase',
'class_key' => 'modDocument',
'published' => 1,
'hidemenu' => 1,
'richtext' => 0,
'parent' => 0,
'menuindex' => 9999999,
// 'uri_override' => 1,
),
);
foreach ($resources as $k => $v) {
/** @var modTemplate $template */
if ($tmp = $modx->getObject('modTemplate', array('templatename' => $v['template']))) {
$v['template'] = $tmp->get('id');
}
/** @var modResource $resource */
if ($tmp = $modx->getObject('modResource', array('alias' => $v['parent']))) {
$v['parent'] = $tmp->get('id');
}
/** @var modResource $resource */
if (!$resource = $modx->getObject('modResource', array('alias' => $k))) {
$resource = $modx->newObject('modResource');
}
$resource->fromArray(array_merge(
array(
'alias' => $k,
'class_key' => 'modDocument',
'content' => isset($v['content']) ? $v['content'] : file_get_contents(MODX_CORE_PATH . 'components/stone/elements/resources/resource.' . $k . '.tpl')
), $v
), '', true, true);
$resource->save();
}
break;
case xPDOTransport::ACTION_UNINSTALL:
break;
}
return true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment