From: Andrey Kutejko Date: Wed, 20 Aug 2014 22:51:25 +0000 (+0300) Subject: move models lists to legacy orm app X-Git-Tag: 0.6~24 X-Git-Url: https://git.andy128k.dev/?a=commitdiff_plain;h=b8f3b361b9953b0538f02822c304327d111d5151;p=ipf-legacy-orm.git move models lists to legacy orm app --- diff --git a/ipf/legacy_orm/app.php b/ipf/legacy_orm/app.php index 0376699..8aa0019 100644 --- a/ipf/legacy_orm/app.php +++ b/ipf/legacy_orm/app.php @@ -2,9 +2,37 @@ class IPF_Legacy_ORM_App extends IPF_Application { - public function __construct() + private static $appModels = array(); + + public static function appModelList($app) { - parent::__construct(); + if (!array_key_exists($app->getName(), self::$appModels)) { + $models = array(); + try { + $it = new DirectoryIterator($app->getPath().DIRECTORY_SEPARATOR.'models'); + foreach ($it as $file) { + $e = explode('.', $file->getFileName(), 2); + if (count($e) == 2 && $e[1] === 'php') { + $models[] = $e[0]; + } + } + } catch (RuntimeException $e) { + // nothing to do + } + + // reorder models according to a given option + if (method_exists($app, 'admin_models_order')) { + $ordered = $app->admin_models_order(); + foreach ($ordered as $modelname) { + if (!in_array($modelname, $models)) + throw new IPF_Exception_Panic("Model \"$modelname\" does not exist."); + } + $models = array_merge($ordered, array_diff($models, $ordered)); + } + + self::$appModels[$app->getName()] = $models; + } + return self::$appModels[$app->getName()]; } public function commands() diff --git a/ipf/legacy_orm/commands/buildmodels.php b/ipf/legacy_orm/commands/buildmodels.php index 3aa84b5..0e2e9b8 100644 --- a/ipf/legacy_orm/commands/buildmodels.php +++ b/ipf/legacy_orm/commands/buildmodels.php @@ -23,7 +23,7 @@ class IPF_Legacy_ORM_Command_BuildModels { $models = array(); foreach ($project->frameworkApps() as $app) - $models = array_merge($models, $app->modelList()); + $models = array_merge($models, IPF_Legacy_ORM_App::appModelList($app)); return $models; } } diff --git a/ipf/legacy_orm/commands/syncdb.php b/ipf/legacy_orm/commands/syncdb.php index cf1afcc..02b550f 100644 --- a/ipf/legacy_orm/commands/syncdb.php +++ b/ipf/legacy_orm/commands/syncdb.php @@ -13,7 +13,7 @@ class IPF_Legacy_ORM_Command_SyncDB $models = array(); foreach ($project->appList() as $app) - $models = array_merge($models, $app->modelList()); + $models = array_merge($models, IPF_Legacy_ORM_App::appModelList($app)); IPF_ORM::createTablesFromModels($models); } diff --git a/ipf/legacy_orm/orm.php b/ipf/legacy_orm/orm.php index fb0396f..660c0a9 100644 --- a/ipf/legacy_orm/orm.php +++ b/ipf/legacy_orm/orm.php @@ -207,7 +207,7 @@ final class IPF_ORM public static function generateSqlFromModels($app) { - $sql = IPF_ORM_Manager::connection()->export->exportSortedClassesSql($app->modelList(), false); + $sql = IPF_ORM_Manager::connection()->export->exportSortedClassesSql(IPF_Legacy_ORM_App::appModelList($app), false); $build = ''; foreach ($sql as $query) {