示例#1
0
/**
 * Get an array of data structures from the database, and allow all modules
 * to extend them.  This function will call hook_data() to get the data and
 * hook_data_alter() to allow modules to alter the data.
 * @param $type The type of data.
 * @param $opts An associative array of options.
 * @return An array of data structures.
 */
function crm_get_data($type, $opts = array())
{
    // Get the base data
    $hook = "{$type}_data";
    if (!function_exists($hook)) {
        error_register('No such data type: ' . $type);
        die;
    }
    $data = call_user_func($hook, $opts);
    if (!empty($data)) {
        // Let other modules extend the data
        foreach (module_list() as $module) {
            // Make sure module is really installed
            $rev_hook = "{$module}_revision";
            $hook = "{$module}_data_alter";
            if (function_exists($hook)) {
                if (module_get_schema_revision($module) != call_user_func($rev_hook)) {
                    error_register("Database schema needs to be upgraded for module {$module}.");
                    continue;
                }
                $data = call_user_func($hook, $type, $data, $opts);
                // Make sure the hook actually returned data
                if (is_null($data)) {
                    error_register('Hook returned null: ' . $hook);
                }
            }
        }
    }
    return $data;
}
示例#2
0
/**
 * @return a table structure of modules and their upgrade status.
 */
function module_upgrade_table()
{
    if (!user_access('module_upgrade')) {
        return '';
    }
    $table = array('id' => '', 'class' => '', 'columns' => array(array('title' => 'Module'), array('title' => 'Old'), array('title' => 'New'), array('title' => 'Needs upgrade?')), 'rows' => array());
    $rows = array();
    foreach (module_list() as $module) {
        $old_rev = module_get_schema_revision($module);
        $new_rev = module_get_code_revision($module);
        $row = array();
        $row[] = $module;
        $row[] = $old_rev;
        $row[] = $new_rev;
        $row[] = $new_rev > $old_rev ? '<strong>Yes</strong>' : 'No';
        $table['rows'][] = $row;
    }
    return $table;
}