upgrade menu using restore defaults, be accountable for permissions

This commit is contained in:
Nuno Miguel Reis
2012-10-11 21:15:27 +00:00
parent d9526ff91e
commit 906dddb976
+76 -37
View File
@@ -94,10 +94,10 @@
$sql .= "menu_item_link, "; $sql .= "menu_item_link, ";
$sql .= "menu_item_category, "; $sql .= "menu_item_category, ";
if (strlen($menu_item_order) > 0) { if (strlen($menu_item_order) > 0) {
$sql .= "menu_item_order, "; $sql .= "menu_item_order, ";
} }
if (strlen($menu_item_parent_uuid) > 0) { if (strlen($menu_item_parent_uuid) > 0) {
$sql .= "menu_item_parent_uuid, "; $sql .= "menu_item_parent_uuid, ";
} }
$sql .= "menu_item_description "; $sql .= "menu_item_description ";
$sql .= ") "; $sql .= ") ";
@@ -110,18 +110,18 @@
$sql .= "'$menu_item_path', "; $sql .= "'$menu_item_path', ";
$sql .= "'$menu_item_category', "; $sql .= "'$menu_item_category', ";
if (strlen($menu_item_order) > 0) { if (strlen($menu_item_order) > 0) {
$sql .= "'$menu_item_order', "; $sql .= "'$menu_item_order', ";
} }
if (strlen($menu_item_parent_uuid) > 0) { if (strlen($menu_item_parent_uuid) > 0) {
$sql .= "'$menu_item_parent_uuid', "; $sql .= "'$menu_item_parent_uuid', ";
} }
$sql .= "'$menu_item_description' "; $sql .= "'$menu_item_description' ";
$sql .= ")"; $sql .= ")";
if ($menu_item_uuid == $menu_item_parent_uuid) { if ($menu_item_uuid == $menu_item_parent_uuid) {
//echo $sql."<br />\n"; //echo $sql."<br />\n";
} }
else { else {
$db->exec(check_sql($sql)); $db->exec(check_sql($sql));
} }
unset($sql); unset($sql);
//set the menu languages //set the menu languages
@@ -150,42 +150,81 @@
} }
} }
} }
} }
foreach($apps as $row) {
//if there are no groups listed in v_menu_item_groups under menu_uuid then add the default groups foreach ($row['permissions'] as $menu) {
$sql = "select count(*) as count from v_menu_item_groups "; //set the variables
$sql .= "where menu_uuid = '".$this->menu_uuid."' "; if ($menu['groups']) {
$prep_statement = $db->prepare($sql); foreach ($menu['groups'] as $group) {
$prep_statement->execute(); //if the item uuid is not currently in the db then add it
$sub_result = $prep_statement->fetch(PDO::FETCH_ASSOC); $sql = "select * from v_group_permissions ";
unset ($prep_statement); $sql .= "where permission_name = '".$menu['name']."' ";
if ($sub_result['count'] == 0) { $sql .= "and group_name = '$group' ";
//no menu item groups found add the defaults $prep_statement = $db->prepare(check_sql($sql));
foreach($apps as $app) { if ($prep_statement) {
foreach ($app['menu'] as $sub_row) { $prep_statement->execute();
foreach ($sub_row['groups'] as $group) { $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
//add the record unset ($prep_statement);
$sql = "insert into v_menu_item_groups "; if (count($result) == 0) {
$sql .= "("; //insert the default menu into the database
$sql .= "menu_uuid, "; $sql = "insert into v_group_permissions ";
$sql .= "menu_item_uuid, "; $sql .= "(";
$sql .= "group_name "; $sql .= "group_permission_uuid, ";
$sql .= ")"; $sql .= "domain_uuid, ";
$sql .= "values "; $sql .= "permission_name, ";
$sql .= "("; $sql .= "group_name ";
$sql .= "'".$this->menu_uuid."', "; $sql .= ") ";
$sql .= "'".$sub_row['uuid']."', "; $sql .= "values ";
$sql .= "'".$group."' "; $sql .= "(";
$sql .= ")"; $sql .= "'".uuid()."', ";
$db->exec($sql); $sql .= "'".$_SESSION["domain_uuid"]."', ";
unset($sql); $sql .= "'".$menu['name']."', ";
$sql .= "'".$group."' ";
$sql .= ");";
$db->exec(check_sql($sql));
unset($sql);
}
} }
} }
} }
}
} }
//save the changes to the database //if there are no groups listed in v_menu_item_groups under menu_uuid then add the default groups
//$db->commit();
foreach($apps as $app) {
foreach ($app['menu'] as $sub_row) {
foreach ($sub_row['groups'] as $group) {
$sql = "select count(*) as count from v_menu_item_groups ";
$sql .= "where menu_item_uuid = '".$sub_row['uuid']."' ";
$sql .= "and group_name = '$group' ";
$prep_statement = $db->prepare($sql);
$prep_statement->execute();
$sub_result = $prep_statement->fetch(PDO::FETCH_ASSOC);
unset ($prep_statement);
if ($sub_result['count'] == 0) {
//no menu item groups found add the defaults
//add the record
$sql = "insert into v_menu_item_groups ";
$sql .= "(";
$sql .= "menu_uuid, ";
$sql .= "menu_item_uuid, ";
$sql .= "group_name ";
$sql .= ")";
$sql .= "values ";
$sql .= "(";
$sql .= "'".$this->menu_uuid."', ";
$sql .= "'".$sub_row['uuid']."', ";
$sql .= "'".$group."' ";
$sql .= ")";
$db->exec($sql);
unset($sql);
}
}
}
}
} //end function } //end function
//create the menu //create the menu