]> git.andy128k.dev Git - ipf.git/commitdiff
load all models on admin pages only
authorAndrey Kutejko <andy128k@gmail.com>
Wed, 20 Aug 2014 22:13:35 +0000 (01:13 +0300)
committerAndrey Kutejko <andy128k@gmail.com>
Wed, 20 Aug 2014 22:13:35 +0000 (01:13 +0300)
ipf/admin/app.php
ipf/admin/commands/syncperms.php
ipf/project.php

index 3813517d2a853983129a8215fb763bf2ce3e464e..a51ab0e6bfa4c973d581711d8fa91ca3e36a87c4 100644 (file)
@@ -53,10 +53,11 @@ class IPF_Admin_App extends IPF_Application
         elseif ( (!$request->user->is_staff) && (!$request->user->is_superuser) )
             $ok = false;
 
-        if ($ok)
-            return true;
-        else
+        if (!$ok)
             return new IPF_HTTP_Response_Redirect(IPF_HTTP_URL::urlForView('IPF_Admin_Views_Login'));
+
+        IPF_Project::getInstance()->loadAllModels();
+        return true;
     }
 
     static function appByModel($model)
index 692d701f010135d8851abdc3445b001ae4d794b9..1811cfd87e4343a9ee63c7d7ccbd521918daa42d 100644 (file)
@@ -9,12 +9,11 @@ class IPF_Admin_Command_SyncPerms
     {
         print "Create/Update permissions from model classes\n";
 
-        $project = IPF_Project::getInstance();
-        $project->loadAllModels();
+        IPF_Admin_App::loadAllModels();
 
         print "COLLECTED PERMS:\n----\n";
         $permissions = array();
-        foreach ($project->appList() as $appname => $app) {
+        foreach (IPF_Project::getInstance()->appList() as $appname => $app) {
             foreach ($app->modelList() as $modelName) {
                 $adminModel = IPF_Admin_Model::getModelAdmin($modelName);
                 if ($adminModel) {
index 01c16aa66bcd211b9b2c7bf99b972fb024b78e96..4e2a595705596d097ee353f8fabd999932cb37da 100644 (file)
@@ -78,13 +78,6 @@ 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()
     {
         \PFF\Container::setFactory('databaseConnection', array('IPF_Database', 'connect'));
@@ -97,8 +90,6 @@ final class IPF_Project
             $cli = new IPF_Cli;
             $cli->run();
         } else {
-            $this->loadAllModels();
-
             $this->request = new IPF_HTTP_Request;
             $this->router->dispatch($this->request);
             $this->request = null;