]> git.andy128k.dev Git - ipf.git/commitdiff
move syncperms command to admin app
authorAndrey Kutejko <andy128k@gmail.com>
Wed, 20 Aug 2014 22:03:31 +0000 (01:03 +0300)
committerAndrey Kutejko <andy128k@gmail.com>
Wed, 20 Aug 2014 22:03:31 +0000 (01:03 +0300)
ipf/admin/app.php
ipf/admin/commands/syncperms.php [new file with mode: 0644]
ipf/auth/app.php
ipf/cli.php
ipf/command/syncperms.php [deleted file]

index ba22f7bcdcae983971bbe5673b34b9a65a626741..3813517d2a853983129a8215fb763bf2ce3e464e 100644 (file)
@@ -108,5 +108,12 @@ class IPF_Admin_App extends IPF_Application
         
         return $perms;
     }
+
+    public function commands()
+    {
+        return array(
+            new IPF_Admin_Command_SyncPerms,
+        );
+    }
 }
 
diff --git a/ipf/admin/commands/syncperms.php b/ipf/admin/commands/syncperms.php
new file mode 100644 (file)
index 0000000..692d701
--- /dev/null
@@ -0,0 +1,67 @@
+<?php
+
+class IPF_Admin_Command_SyncPerms
+{
+    public $command = 'syncperms';
+    public $description = 'Create/Update permissions from model classes';
+
+    public function run($args=null)
+    {
+        print "Create/Update permissions from model classes\n";
+
+        $project = IPF_Project::getInstance();
+        $project->loadAllModels();
+
+        print "COLLECTED PERMS:\n----\n";
+        $permissions = array();
+        foreach ($project->appList() as $appname => $app) {
+            foreach ($app->modelList() as $modelName) {
+                $adminModel = IPF_Admin_Model::getModelAdmin($modelName);
+                if ($adminModel) {
+                    foreach ($adminModel->getPerms(null) as $permName) {
+                        $name = get_class($app).'|'.$modelName.'|'.$permName;
+                        $permissions[$name] = array($app, $modelName, $permName);
+                        print $name."\n";
+                    }
+                }
+            }
+        }
+        print "\n";
+
+        print "EXISTING PERMS:\n----\n";
+        $existingPerms = array();
+        foreach (Permission::table()->findAll() as $model) {
+            $existingPerms[$model->name] = $model;
+            print $model->name."\n";
+        }
+        print "\n";
+
+
+        $toDel = array_diff(array_keys($existingPerms), array_keys($permissions));
+
+        print "2DEL:\n----\n".implode("\n", $toDel)."\n----\n";
+
+        if (count($toDel)) {
+            Permission::query()
+                ->delete()
+                ->where("name in ('".implode("','", $toDel)."')")
+                ->execute();
+        }
+
+
+        $toAdd = array_diff(array_keys($permissions), array_keys($existingPerms));
+
+        print "2ADD:\n----\n".implode("\n", $toAdd)."\n----\n";
+
+        foreach ($toAdd as $name) {
+            $app = $permissions[$name][0];
+            $admin = IPF_Admin_Model::getModelAdmin($permissions[$name][1]);
+
+            $model = new Permission;
+            $model->name = $name;
+            $model->title = $app->getTitle().' | '.$admin->verbose_name().' | '.ucfirst($permissions[$name][2]);
+            $model->save();
+        }
+    }
+}
+
index 55bd770f856fbf31c1c963070a30afbce394bdca..e2330b77bd5a7e964594dec74b38ff5a1f4f9025 100644 (file)
@@ -33,65 +33,6 @@ class IPF_Auth_App extends IPF_Application
         );
     }
 
-    static function createPermissionsFromModels()
-    {
-        $permsTable = Permission::table();
-
-        $project = IPF_Project::getInstance();
-        $project->loadAllModels();
-
-        print "COLLECTED PERMS:\n----\n";
-        $permissions = array();
-        foreach ($project->appList() as $appname => $app) {
-            foreach ($app->modelList() as $modelName) {
-                $adminModel = IPF_Admin_Model::getModelAdmin($modelName);
-                if ($adminModel) {
-                    foreach ($adminModel->getPerms(null) as $permName) {
-                        $name = get_class($app).'|'.$modelName.'|'.$permName;
-                        $permissions[$name] = array($app, $modelName, $permName);
-                        print $name."\n";
-                    }
-                }
-            }
-        }
-        print "\n";
-
-        print "EXISTING PERMS:\n----\n";
-        $existingPerms = array();
-        foreach ($permsTable->findAll() as $model) {
-            $existingPerms[$model->name] = $model;
-            print $model->name."\n";
-        }
-        print "\n";
-
-
-        $toDel = array_diff(array_keys($existingPerms), array_keys($permissions));
-
-        print "2DEL:\n----\n".implode("\n", $toDel)."\n----\n";
-
-        if (count($toDel)) {
-            $permsTable->createQuery()
-                ->delete()
-                ->where("name in ('".implode("','", $toDel)."')")
-                ->execute();
-        }
-
-
-        $toAdd = array_diff(array_keys($permissions), array_keys($existingPerms));
-
-        print "2ADD:\n----\n".implode("\n", $toAdd)."\n----\n";
-
-        foreach ($toAdd as $name) {
-            $app = $permissions[$name][0];
-            $admin = IPF_Admin_Model::getModelAdmin($permissions[$name][1]);
-
-            $model = new Permission;
-            $model->name = $name;
-            $model->title = $app->getTitle().' | '.$admin->verbose_name().' | '.ucfirst($permissions[$name][2]);
-            $model->save();
-        }
-    }
-
     static function ArePermissionsEnabled()
     {
         try {
index ff56646eaff7e6fc335e2e7b4d1c88a4f374659c..e9bc85ff4bd426d3b0ff0f1818c2542946603c43 100644 (file)
@@ -27,7 +27,6 @@ class IPF_Cli
                 new IPF_Command_Unpack,
                 new IPF_Command_CreateMigration,
                 new IPF_Command_Migrate,
-                new IPF_Command_SyncPerms,
             ),
         );
 
diff --git a/ipf/command/syncperms.php b/ipf/command/syncperms.php
deleted file mode 100644 (file)
index f2158d0..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-<?php
-
-class IPF_Command_SyncPerms
-{
-    public $command = 'syncperms';
-    public $description = 'Create/Update permissions from model classes';
-
-    public function run($args=null)
-    {
-        print "Create/Update permissions from model classes\n";
-        IPF_Auth_App::createPermissionsFromModels();
-    }
-}
-