From 382bba0f73ba37ca0e362cebc432bd669a50ebd8 Mon Sep 17 00:00:00 2001 From: Andrey Kutejko Date: Thu, 21 Aug 2014 01:03:31 +0300 Subject: [PATCH] move syncperms command to admin app --- ipf/admin/app.php | 7 ++++ ipf/admin/commands/syncperms.php | 67 ++++++++++++++++++++++++++++++++ ipf/auth/app.php | 59 ---------------------------- ipf/cli.php | 1 - ipf/command/syncperms.php | 14 ------- 5 files changed, 74 insertions(+), 74 deletions(-) create mode 100644 ipf/admin/commands/syncperms.php delete mode 100644 ipf/command/syncperms.php diff --git a/ipf/admin/app.php b/ipf/admin/app.php index ba22f7b..3813517 100644 --- a/ipf/admin/app.php +++ b/ipf/admin/app.php @@ -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 index 0000000..692d701 --- /dev/null +++ b/ipf/admin/commands/syncperms.php @@ -0,0 +1,67 @@ +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(); + } + } +} + diff --git a/ipf/auth/app.php b/ipf/auth/app.php index 55bd770..e2330b7 100644 --- a/ipf/auth/app.php +++ b/ipf/auth/app.php @@ -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 { diff --git a/ipf/cli.php b/ipf/cli.php index ff56646..e9bc85f 100644 --- a/ipf/cli.php +++ b/ipf/cli.php @@ -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 index f2158d0..0000000 --- a/ipf/command/syncperms.php +++ /dev/null @@ -1,14 +0,0 @@ -