'Table external link templates.', 'fields' => [ 'id' => [ 'type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => '', 'description' => 'Name of the ext_link being referenced.', ], 'title' => [ 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'description' => 'The link title', ], 'link' => [ 'type' => 'varchar', 'length' => 2048, 'not null' => TRUE, 'description' => 'The link url template', ], 'category' => [ 'type' => 'varchar', 'length' => 255, 'description' => 'The link category', ], 'weight' => [ 'type' => 'int', 'not null' => TRUE, 'default' => 0, 'description' => 'Weight of filter within format.', ], 'status' => [ 'type' => 'int', 'not null' => TRUE, 'default' => 0, 'description' => 'External link enabled status. (1 = enabled, 0 = disabled)', ], ], 'primary key' => ['id'], 'indexes' => [ 'list' => ['weight', 'id'], ], ]; return $schema; } /** * implements hook_install() */ function ext_links_install() { $links_templates = migrate_old_ext_links(); foreach ($links_templates as $ext_link){ db_delete('variable') ->condition('name', "ext_links_" . $ext_link->id . '_%', 'LIKE') ->execute(); } variable_set('ext_links_appearance_grouped', variable_get('ext_links_options', 0) != 1 ? 1 : 0 ); variable_del('ext_links_options'); } /** * Implements hook_uninstall(). */ function ext_links_uninstall() { db_drop_table('ext_links'); } /** * Update function to migrate previous versions */ function ext_links_update_7001(){ $connection_info = Database::parseConnectionInfo(); $db_prefix = $connection_info['default']['default']['prefix']; foreach(ext_links_schema() as $table_name => $schema){ if(!db_table_exists($db_prefix . $table_name)){ db_create_table($db_prefix . $table_name, $schema); } } ext_links_install(); return "ext_links table created and old settings migrated."; } /** * Update ext_link to cdm_tokens functionality */ function ext_links_update_7002(){ $tasks_performed = []; $column_glue_exists = db_query("SHOW COLUMNS FROM {ext_links} LIKE 'glue';")->rowCount(); if($column_glue_exists){ db_query("ALTER TABLE {ext_links} DROP COLUMN glue;"); $tasks_performed[] = "ext_links table: Column glue removed."; } db_query("ALTER TABLE {ext_links} MODIFY COLUMN link varchar(2048) NOT NULL COMMENT 'The link url template';"); $tasks_performed[] = "ext_links.link modified to varchar 2048."; ext_links_template_links_update(); $tasks_performed[] = "ext_link template links updated."; return join("; \n", $tasks_performed); } /** * Migrates old ext link templates from drupal vars to the ext_link table. */ function migrate_old_ext_links(){ $links_templates = ext_links_templates(); foreach ($links_templates as $ext_link){ $ext_link = _ext_links_merge_old_vars($ext_link); ext_links_save($ext_link); } return $links_templates; } /** * Updates the ext_links.link column with new urls from the default templates. */ function ext_links_template_links_update(){ $template_default_arrays = ext_links_template_defaults(); foreach ($template_default_arrays as $template_array) { $return = db_merge('ext_links') ->key(['id' => $template_array['id']]) ->fields([ 'link' => $template_array['link'], ]) ->execute(); } } /** * Merge the old settings stored in drupal vars into the ext_link template object * @param $ext_link object * * @return object * The ext link template */ function _ext_links_merge_old_vars($ext_link){ $ext_link_id = $ext_link->id; $ext_link->status = variable_get("ext_links_${ext_link_id}_check", $ext_link->status); $ext_link->link = variable_get("ext_links_${ext_link_id}_link", $ext_link->link); $ext_link->title = variable_get("ext_links_${ext_link_id}_text", $ext_link->title); return $ext_link; }