Skip to content

Instantly share code, notes, and snippets.

@antixrist
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antixrist/be29c8381214654af04e to your computer and use it in GitHub Desktop.
Save antixrist/be29c8381214654af04e to your computer and use it in GitHub Desktop.
Resolver
<?php
if ($object->xpdo) {
/** @var modX $modx */
$modx =& $object->xpdo;
/** @var array $options */
switch ($options[xPDOTransport::PACKAGE_ACTION]) {
case xPDOTransport::ACTION_INSTALL:
$modelPath = $modx->getOption('mypkg.core_path', null, $modx->getOption('core_path') . 'components/mypkg/') . 'model/';
$modx->addPackage('mypkg', $modelPath);
$manager = $modx->getManager();
$objects = array(
'mypkgClient',
'mypkgOffice',
'mypkgOfficeManagerMember',
'mypkgOrder',
);
$dontRemoveObjects = array(
'mypkgClient',
'mypkgClientAddress',
'mypkgOffice',
'mypkgOfficeManagerMember',
'mypkgOrder',
);
$forceRemoveObjects = array(
// 'mypkgClientAddress',
);
foreach ($objects as $tmp) {
if (!in_array($tmp, $dontRemoveObjects) || in_array($tmp, $forceRemoveObjects)) {
$manager->removeObjectContainer($tmp);
}
$manager->createObjectContainer($tmp);
}
$mypkgCorePath = $modx->getOption('mypkg.core_path');
$corePath = ($mypkgCorePath) ? $mypkgCorePath : $modx->getOption('core_path') . 'components/mypkg/';
$metaFile = $mypkgCorePath .'model/mypkg/metadata.mysql.php';
$code = file_get_contents($metaFile);
$neededCode = <<<'CODE'
/* generated from resolver */
$this->map['modUser']['aggregates']['Clients'] = array(
'class' => 'mypkgClient',
'local' => 'id',
'foreign' => 'managedby',
'cardinality' => 'many',
'owner' => 'local',
);
CODE;
if (strpos($code, $neededCode) === FALSE) {
file_put_contents($metaFile, $neededCode, FILE_APPEND);
}
$modx->removeExtensionPackage('mypkg');
$modx->addExtensionPackage('mypkg', $modx->getOption('mypkg.core_path', null, '[[++core_path]]components/mypkg/') .'model/mypkg/');
$level = $modx->getLogLevel();
$modx->setLogLevel(xPDO::LOG_LEVEL_FATAL);
$manager->addField('mypkgOffice', 'settings');
$manager->addField('mypkgOffice', 'city');
$manager->addField('mypkgOffice', 'doctpls');
$manager->addField('mypkgClient', 'actual_address');
// $manager->addIndex('mypkgItem', 'item_indexgrp');
$modx->setLogLevel($level);
break;
case xPDOTransport::ACTION_UPGRADE:
break;
case xPDOTransport::ACTION_UNINSTALL:
$modx->removeExtensionPackage('mypkg');
break;
}
}
return true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment