Skip to content

Instantly share code, notes, and snippets.

@Fi1osof
Created November 13, 2014 09:21
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 Fi1osof/8aaa4a2ebb040b1c9436 to your computer and use it in GitHub Desktop.
Save Fi1osof/8aaa4a2ebb040b1c9436 to your computer and use it in GitHub Desktop.
<?php
protected function _xpdo_remap(array $table_rebuild = array()){
$model_path = $this->getOption('modelPath');
$packPath = $model_path . __CLASS__ . '/';
$schema_file = $model_path . 'schema/modxrealty.mysql.schema.xml';
if(file_exists($schema_file)){
$this->modx->log(modX::LOG_LEVEL_INFO, 'START remap modxRealty Package!!!.');
$manager = $this->modx->getManager();
$generator = $manager->getGenerator();
if(is_dir($packPath)){
$mapFiles = glob($packPath.'/*.map.inc.php');
foreach($mapFiles as $mapFile){
if(is_writable($mapFile)){
unlink($mapFile);
$this->modx->log(modX::LOG_LEVEL_INFO, 'Completely delete map file "'.basename($mapFile).'" for rebuild map from schema.');
}else $this->modx->log(modX::LOG_LEVEL_ERROR, 'map file "'.$mapFile.'" could not be deleted, file not writable');
}
}
$schema = file_get_contents($schema_file);
$classes = array();
if(preg_match_all('@<object.+?class="(?<class>\w+?)"@si',$schema,$matches) && is_array($matches&#91;'class'&#93;) && count($matches&#91;'class'&#93;)){
$classes = $matches&#91;'class'&#93;;
}else $this->modx->log(modx::LOG_LEVEL_ERROR,'classes in schema file not found');
$generator->parseSchema($schema_file,$model_path);
$this->modx->addPackage('modxRealty',$this->config&#91;'modelPath'&#93;);
if(count($table_rebuild) > 0){
$oldLevel = $this->modx->getLogLevel();
$this->modx->setLogLevel(xPDO::LOG_LEVEL_INFO);
foreach($table_rebuild as $className){
if(in_array($className,$classes)){
$this->modx->log(xPDO::LOG_LEVEL_INFO, 'Object container for "'.$className.'" set remove');
$manager->removeObjectContainer($className);
}else $this->modx->log(xPDO::LOG_LEVEL_INFO, 'Object container count not be removed for "'.$className.'" not exists in schema');
}
$this->modx->setLogLevel($oldLevel);
}
foreach($classes as $className){
if($manager->createObjectContainer($className)){
$this->modx->log(modX::LOG_LEVEL_INFO, 'Object container "'.$className.'" to create');
}
}
$this->modx->log(modX::LOG_LEVEL_INFO, 'FINISH Remap package modxRealty! is Successfully!!');
}else $this->modx->log(modx::LOG_LEVEL_ERROR,'schema file not found "'.$schema_file.'"');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment