예제 #1
0
 public function testwrite_logic_file()
 {
     //execute the method and test if it returns expected values,
     //check if file is created and contains expected contents
     $vfs = vfsStream::setup('custom/modules/TEST_Test');
     if ($vfs->hasChild('logic_hooks.php') == true) {
         unlink('custom/modules/TEST_Test/logic_hooks.php');
         rmdir('custom/modules/TEST_Test');
     }
     $expectedContents = "<?php\n// Do not store anything in this file that is not part of the array or the hook version.  This file will\t\n// be automatically rebuilt in the future. \n \$hook_version = 1; \n\$hook_array = Array(); \n// position, file, function \n\$hook_array['after_ui_footer'] = Array(); \n\$hook_array['after_ui_footer'][] = Array(10, 'popup_onload', 'modules/SecurityGroups/AssignGroups.php','AssignGroups', 'popup_onload'); \n\$hook_array['after_ui_frame'] = Array(); \n\$hook_array['after_ui_frame'][] = Array(20, 'mass_assign', 'modules/SecurityGroups/AssignGroups.php','AssignGroups', 'mass_assign'); \n\$hook_array['after_ui_frame'][] = Array(1, 'Load Social JS', 'custom/include/social/hooks.php','hooks', 'load_js'); \n\$hook_array['after_save'] = Array(); \n\$hook_array['after_save'][] = Array(30, 'popup_select', 'modules/SecurityGroups/AssignGroups.php','AssignGroups', 'popup_select'); \n\$hook_array['after_save'][] = Array(1, 'AOD Index Changes', 'modules/AOD_Index/AOD_LogicHooks.php','AOD_LogicHooks', 'saveModuleChanges'); \n\$hook_array['after_delete'] = Array(); \n\$hook_array['after_delete'][] = Array(1, 'AOD Index changes', 'modules/AOD_Index/AOD_LogicHooks.php','AOD_LogicHooks', 'saveModuleDelete'); \n\$hook_array['after_restore'] = Array(); \n\$hook_array['after_restore'][] = Array(1, 'AOD Index changes', 'modules/AOD_Index/AOD_LogicHooks.php','AOD_LogicHooks', 'saveModuleRestore'); \n\n\n\n?>";
     write_logic_file('TEST_Test', $expectedContents);
     //Check file created
     $this->assertFileExists('custom/modules/TEST_Test/logic_hooks.php');
     $actualContents = file_get_contents('custom/modules/TEST_Test/logic_hooks.php');
     $this->assertSame($expectedContents, $actualContents);
     $expectedArray = $this->getTestHook();
     $actualArray = get_hook_array('TEST_Test');
     $this->assertSame($expectedArray, $actualArray);
     unlink('custom/modules/TEST_Test/logic_hooks.php');
     rmdir('custom/modules/TEST_Test');
 }
예제 #2
0
function remove_logic_hook($module_name, $event, $action_array)
{
    require_once 'include/utils/logic_utils.php';
    $add_logic = false;
    if (file_exists("custom/modules/" . $module_name . "/logic_hooks.php")) {
        // The file exists, let's make sure the hook is there
        $hook_array = get_hook_array($module_name);
        if (check_existing_element($hook_array, $event, $action_array) == true) {
            // The hook is there, time to take it out.
            foreach ($hook_array[$event] as $i => $hook) {
                // We don't do a full comparison below just in case the filename changes
                if ($hook[0] == $action_array[0] && $hook[1] == $action_array[1] && $hook[3] == $action_array[3] && $hook[4] == $action_array[4]) {
                    unset($hook_array[$event][$i]);
                }
            }
            $new_contents = replace_or_add_logic_type($hook_array);
            write_logic_file($module_name, $new_contents);
        }
    }
}
예제 #3
0
function check_logic_hook_file($module_name, $event, $action_array)
{
    require_once 'include/utils/logic_utils.php';
    $add_logic = false;
    if (file_exists("custom/modules/{$module_name}/logic_hooks.php")) {
        $hook_array = get_hook_array($module_name);
        if (check_existing_element($hook_array, $event, $action_array) == true) {
            //the hook at hand is present, so do nothing
        } else {
            $add_logic = true;
            $logic_count = count($hook_array[$event]);
            if ($action_array[0] == "") {
                $action_array[0] = $logic_count + 1;
            }
            $hook_array[$event][] = $action_array;
        }
        //end if the file exists already
    } else {
        $add_logic = true;
        if ($action_array[0] == "") {
            $action_array[0] = 1;
        }
        $hook_array = array();
        $hook_array[$event][] = $action_array;
        //end if else file exists already
    }
    if ($add_logic == true) {
        //reorder array by element[0]
        //$hook_array = reorder_array($hook_array, $event);
        //!!!Finish this above TODO
        $new_contents = replace_or_add_logic_type($hook_array);
        write_logic_file($module_name, $new_contents);
        //end if add_element is true
    }
    //end function check_logic_hook_file
}