-
-
Save antixrist/be29c8381214654af04e to your computer and use it in GitHub Desktop.
Resolver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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