-
-
Save Fi1osof/8aaa4a2ebb040b1c9436 to your computer and use it in GitHub Desktop.
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 | |
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['class']) && count($matches['class'])){ | |
$classes = $matches['class']; | |
}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['modelPath']); | |
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