From e74b21e30b4dfe0a8a1a21e4ca8f26080662e762 Mon Sep 17 00:00:00 2001 From: Andrey Kutejko Date: Sun, 14 Jul 2013 12:43:51 +0300 Subject: [PATCH] load all models on start (required by syncperms command and admin app) --- ipf/auth/app.php | 7 +++++-- ipf/command/syncperms.php | 4 +--- ipf/project.php | 8 ++++++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/ipf/auth/app.php b/ipf/auth/app.php index a5295a9..8ff7be8 100644 --- a/ipf/auth/app.php +++ b/ipf/auth/app.php @@ -33,12 +33,15 @@ class IPF_Auth_App extends IPF_Application $request->session->setData('logout_time', gmdate('Y-m-d H:i:s')); } - static function createPermissionsFromModels(array $apps) + static function createPermissionsFromModels() { $permsTable = IPF_ORM::getTable('Permission'); + $project = IPF_Project::getInstance(); + $project->loadAllModels(); + $permissions = array(); - foreach ($apps as $appname => $app) { + foreach ($project->appList() as $appname => $app) { foreach ($app->modelList() as $modelName) { $adminModel = IPF_Admin_Model::getModelAdmin($modelName); if ($adminModel) { diff --git a/ipf/command/syncperms.php b/ipf/command/syncperms.php index 9aadb85..f2158d0 100644 --- a/ipf/command/syncperms.php +++ b/ipf/command/syncperms.php @@ -8,9 +8,7 @@ class IPF_Command_SyncPerms public function run($args=null) { print "Create/Update permissions from model classes\n"; - - $project = IPF_Project::getInstance(); - return IPF_Auth_App::createPermissionsFromModels($project->appList()); + IPF_Auth_App::createPermissionsFromModels(); } } diff --git a/ipf/project.php b/ipf/project.php index d30aa48..3ba1205 100644 --- a/ipf/project.php +++ b/ipf/project.php @@ -83,6 +83,13 @@ final class IPF_Project return $result; } + public function loadAllModels() + { + foreach ($this->appList() as $appname => $app) + foreach ($app->modelList() as $modelName) + new $modelName; + } + public function run() { if (IPF::get('debug')) { @@ -98,6 +105,7 @@ final class IPF_Project $cli = new IPF_Cli; $cli->run(); } else { + $this->loadAllModels(); $this->router->dispatch(IPF_HTTP_URL::getAction()); } -- 2.49.0