Permalink
Browse files

Merge pull request #469 from mwhitneysdsu/develop

Refactored the Module Builder ACL Migration
  • Loading branch information...
2 parents e33577a + 871ddfc commit 53c29dcf14647060a4d774f5f8291e1db6551741 @seandowney seandowney committed Jun 3, 2012
Showing with 29 additions and 34 deletions.
  1. +29 −34 bonfire/application/core_modules/modulebuilder/views/files/acl_migration.php
@@ -4,11 +4,9 @@
class Migration_Install_'.$module_name_lower.'_permissions extends Migration {
- public function up()
- {
- $prefix = $this->db->dbprefix;
+ // permissions to migrate
+ private $permission_values = array(';
- // permissions';
foreach($contexts as $context)
{
if ($context != 'public')
@@ -25,17 +23,30 @@ public function up()
$action_permission = $permission . $action_name;
$action_status = 'active';
$action_description = '';
- $acl_migrations .= '
- $permissions_data = array(\'name\' => \''.$action_permission.'\', \'description\' => \''.$action_description.'\', \'status\' => \''.$action_status.'\',);
- $this->db->insert("{$prefix}permissions", $permissions_data);
- $role_permissions_data = array(\'role_id\' => \''.$role_id.'\', \'permission_id\' => $this->db->insert_id(),);
- $this->db->insert("{$prefix}role_permissions", $role_permissions_data);';
+ $acl_migrations .= '
+ array(\'name\' => \''.$action_permission.'\', \'description\' => \''.$action_description.'\', \'status\' => \''.$action_status.'\',),';
}
}
}
$acl_migrations .= '
+ );
+
+ //--------------------------------------------------------------------
+
+ public function up()
+ {
+ $prefix = $this->db->dbprefix;
+
+ // permissions
+ foreach ($this->permission_values as $permission_value)
+ {
+ $permissions_data = $permission_value;
+ $this->db->insert("{$prefix}permissions", $permissions_data);
+ $role_permissions_data = array(\'role_id\' => \''.$role_id.'\', \'permission_id\' => $this->db->insert_id(),);
+ $this->db->insert("{$prefix}role_permissions", $role_permissions_data);
+ }
}
//--------------------------------------------------------------------
@@ -44,35 +55,19 @@ public function down()
{
$prefix = $this->db->dbprefix;
- // permissions';
-foreach($contexts as $context) {
- if ($context != 'public')
- {
- $permission = '';
- $permission = ucfirst($module_name) .".";
- $permission .= ucfirst($context).".";
- foreach($action_names as $action_name) {
- $action_permission = '';
- $action_name = ucfirst($action_name);
- if($action_name == 'Index') {
- $action_name = 'View';
- }
- $action_permission = $permission . $action_name;
- $acl_migrations .= '
- $query = $this->db->select(\'permission_id\')->get_where("{$prefix}permissions", array(\'name\' => \''.$action_permission.'\',));
- foreach ($query->result_array() as $row)
+ // permissions
+ foreach ($this->permission_values as $permission_value)
{
- $permission_id = $row[\'permission_id\'];
- $this->db->delete("{$prefix}role_permissions", array(\'permission_id\' => $permission_id));
- }
- $this->db->delete("{$prefix}permissions", array(\'name\' => \''.$action_permission.'\'));';
+ $query = $this->db->select(\'permission_id\')->get_where("{$prefix}permissions", array(\'name\' => $permission_value[\'name\'],));
+ foreach ($query->result_array() as $row)
+ {
+ $permission_id = $row[\'permission_id\'];
+ $this->db->delete("{$prefix}role_permissions", array(\'permission_id\' => $permission_id));
+ }
+ $this->db->delete("{$prefix}permissions", array(\'name\' => $permission_value[\'name\']));
}
}
-}
-
-$acl_migrations .= '
- }
//--------------------------------------------------------------------

0 comments on commit 53c29dc

Please sign in to comment.