| 1 |
<?php |
<?php |
| 2 |
// $Id: follow.install,v 1.2 2009/10/30 21:09:28 pwolanin Exp $ |
// $Id: follow.install,v 1.3 2009/11/02 20:25:53 pwolanin Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 10 |
* Implementation of hook_install(). |
* Implementation of hook_install(). |
| 11 |
*/ |
*/ |
| 12 |
function follow_install() { |
function follow_install() { |
| 13 |
return; |
// Add a default link to this site's node RSS feed. |
|
// @todo: Add a default link to this site's node RSS feed. |
|
| 14 |
db_insert('follow_links') |
db_insert('follow_links') |
| 15 |
->fields(array( |
->fields(array( |
| 16 |
'name' => 'self', |
'name' => 'self', |
| 47 |
'default' => 0, |
'default' => 0, |
| 48 |
'description' => "User's {users} uid. Sitewide {follow_links} use uid 0", |
'description' => "User's {users} uid. Sitewide {follow_links} use uid 0", |
| 49 |
), |
), |
| 50 |
'url' => array( |
'path' => array( |
| 51 |
'type' => 'varchar', |
'type' => 'varchar', |
| 52 |
'length' => 255, |
'length' => 255, |
| 53 |
'not null' => TRUE, |
'not null' => TRUE, |
| 54 |
'default' => '', |
'default' => '', |
| 55 |
'description' => 'The url the {follow_links} should point to.', |
'description' => 'The Drupal path or extenal URL the {follow_links} should point to.', |
| 56 |
|
), |
| 57 |
|
'options' => array( |
| 58 |
|
'description' => 'A serialized array of options to be passed to the url() or l() function, such as a query string or HTML attributes.', |
| 59 |
|
'type' => 'text', |
| 60 |
|
'translatable' => TRUE, |
| 61 |
|
'serialize' => TRUE, |
| 62 |
), |
), |
| 63 |
'weight' => array( |
'weight' => array( |
| 64 |
'type' => 'int', |
'type' => 'int', |
| 70 |
), |
), |
| 71 |
'primary key' => array('lid'), |
'primary key' => array('lid'), |
| 72 |
'unique keys' => array( |
'unique keys' => array( |
| 73 |
'name_uid' => array('name', 'uid'), |
'uid_name' => array('uid', 'name'), |
| 74 |
), |
), |
| 75 |
); |
); |
| 76 |
return $schema; |
return $schema; |
| 85 |
variable_del('follow_site_block_user'); |
variable_del('follow_site_block_user'); |
| 86 |
} |
} |
| 87 |
|
|
| 88 |
|
/** |
| 89 |
|
* Update for caching and schema changes. |
| 90 |
|
*/ |
| 91 |
function follow_update_7000() { |
function follow_update_7000() { |
| 92 |
cache_clear_all('follow:networks', 'cache'); |
cache_clear_all('follow:networks', 'cache'); |
| 93 |
return array(); |
$new_schema = array( |
| 94 |
|
'path' => array( |
| 95 |
|
'type' => 'varchar', |
| 96 |
|
'length' => 255, |
| 97 |
|
'not null' => TRUE, |
| 98 |
|
'default' => '', |
| 99 |
|
'description' => 'The Drupal path or extenal URL the {follow_links} should point to.', |
| 100 |
|
), |
| 101 |
|
'options' => array( |
| 102 |
|
'type' => 'text', |
| 103 |
|
'description' => 'A serialized array of options to be passed to the url() or l() function, such as a query string or HTML attributes.', |
| 104 |
|
), |
| 105 |
|
); |
| 106 |
|
// Since we match against just uid in queries, this field must |
| 107 |
|
// come first for the index to be used. |
| 108 |
|
db_drop_unique_key('follow_links', 'name_uid'); |
| 109 |
|
db_add_unique_key('follow_links', 'uid_name', array('uid', 'name')); |
| 110 |
|
db_add_field('follow_links', 'path', $new_schema['path']); |
| 111 |
|
db_add_field('follow_links', 'options', $new_schema['options']); |
| 112 |
|
db_update('follow_links')->fields(array('options' => 'a:0:{}'))->execute(); |
| 113 |
|
return " |
| 114 |
|
db_add_field('follow_links', 'path', \$new_schema['path']); |
| 115 |
|
db_add_field('follow_links', 'options', \$new_schema['options']); |
| 116 |
|
"; |
| 117 |
|
} |
| 118 |
|
|
| 119 |
|
/** |
| 120 |
|
* Update existing data to the new schema. |
| 121 |
|
*/ |
| 122 |
|
function follow_update_7001(&$sandbox = NULL) { |
| 123 |
|
if (!isset($sandbox['max_lid'])) { |
| 124 |
|
$sandbox['current_lid'] = 0; |
| 125 |
|
$sandbox['max_lid'] = db_query('SELECT MAX(lid) FROM {follow_links}')->fetchField(); |
| 126 |
|
} |
| 127 |
|
$links = db_select('follow_links', 'f') |
| 128 |
|
->fields('f', array('lid', 'url')) |
| 129 |
|
->condition('lid', $sandbox['current_lid'], '>') |
| 130 |
|
->range(0, 100) |
| 131 |
|
->orderBy('lid', 'ASC') |
| 132 |
|
->execute(); |
| 133 |
|
foreach ($links as $link) { |
| 134 |
|
$parsed_url = follow_parse_url($link->url); |
| 135 |
|
db_update('follow_links') |
| 136 |
|
->fields(array('path' => $parsed_url['path'], 'options' => serialize($parsed_url['options']))) |
| 137 |
|
->condition('lid', $link->lid) |
| 138 |
|
->execute(); |
| 139 |
|
|
| 140 |
|
$sandbox['current_lid'] = $link->lid; |
| 141 |
|
} |
| 142 |
|
|
| 143 |
|
$sandbox['#finished'] = empty($sandbox['max_lid']) ? 1 : ($sandbox['current_lid'] / $sandbox['max_lid']); |
| 144 |
|
} |
| 145 |
|
|
| 146 |
|
|
| 147 |
|
/** |
| 148 |
|
* Drop old schema column. |
| 149 |
|
*/ |
| 150 |
|
function follow_update_7002() { |
| 151 |
|
db_drop_field('follow_links', 'url'); |
| 152 |
|
return "db_drop_field('follow_links', 'url');"; |
| 153 |
} |
} |
| 154 |
|
|