| 1 |
<?php |
<?php |
| 2 |
|
// $Id$ |
| 3 |
|
/** |
| 4 |
|
* @file |
| 5 |
|
* The (un)install logic for Node Teaser. |
| 6 |
|
*/ |
| 7 |
|
|
| 8 |
|
|
| 9 |
|
/** |
| 10 |
|
* Implementation of hook_install(). |
| 11 |
|
* |
| 12 |
|
* @todo Verify pgsql install. |
| 13 |
|
*/ |
| 14 |
function nodeteaser_install() { |
function nodeteaser_install() { |
| 15 |
|
$success = FALSE; |
| 16 |
|
|
| 17 |
switch ($GLOBALS['db_type']) { |
switch ($GLOBALS['db_type']) { |
| 18 |
case 'mysql': |
case 'mysql': |
| 19 |
case 'mysqli': |
case 'mysqli': |
| 20 |
db_query("CREATE TABLE {nodeteaser} ( |
$result1 = db_query("CREATE TABLE {nodeteaser} ( |
| 21 |
nid int(11) NOT NULL default '0', |
nid int(11) NOT NULL default 0, |
| 22 |
teaser text NOT NULL, |
teaser text NOT NULL, |
| 23 |
KEY nid (nid) |
KEY nid (nid) |
| 24 |
) /*!40100 DEFAULT CHARACTER SET utf8 */;"); |
) /*!40100 DEFAULT CHARACTER SET utf8 */;"); |
| 25 |
|
// Modules are processed in module_implements() by weight, and we |
| 26 |
|
// want Node Teaser's hook_nodeapi() implementation running last. |
| 27 |
|
$result2 = db_query("UPDATE {system} SET weight=99 WHERE name='nodeteaser';"); |
| 28 |
|
|
| 29 |
|
$success = ($result1 && $result2); |
| 30 |
break; |
break; |
| 31 |
case 'pgsql': |
case 'pgsql': |
| 32 |
db_query("CREATE TABLE {nodeteaser} ( |
$result1 = db_query("CREATE TABLE {nodeteaser} ( |
| 33 |
nid int NOT NULL default '0', |
nid int NOT NULL default '0', |
| 34 |
teaser text NOT NULL, |
teaser text NOT NULL, |
| 35 |
KEY nid (nid) |
KEY nid (nid) |
| 36 |
) /*!40100 DEFAULT CHARACTER SET utf8 */;"); |
) /*!40100 DEFAULT CHARACTER SET utf8 */;"); |
| 37 |
|
// Modules are processed in module_implements() by weight, and we |
| 38 |
|
// want Node Teaser's hook_nodeapi() implementation running last. |
| 39 |
|
$result2 = db_query("UPDATE {system} SET weight=99 WHERE name='nodeteaser';"); |
| 40 |
|
|
| 41 |
|
$success = ($result1 && $result2); |
| 42 |
break; |
break; |
| 43 |
} |
} |
| 44 |
|
|
| 45 |
// Notify of changes |
if ($success !== FALSE) { |
| 46 |
drupal_set_message(t('Node teaser module was successfully installed with default options. To customize node teaser, please view the <a href="%settings">node teaser settings page</a>.', array('%settings' => url('admin/settings/nodeteaser')))); |
$link = array('!settings' => l(t('Node Teaser Settings'), 'admin/settings/nodeteaser')); |
| 47 |
|
drupal_set_message(t('Node Teaser was successfully installed with the default options. To customize Node Teaser, please view the !settings page.', $link)); |
| 48 |
|
} |
| 49 |
|
else { |
| 50 |
|
drupal_set_message(t('Node Teaser could not be installed.')); |
| 51 |
|
} |
| 52 |
} |
} |
| 53 |
|
|
| 54 |
|
|
| 55 |
|
/** |
| 56 |
|
* Implementation of hook_update_N(). |
| 57 |
|
*/ |
| 58 |
function nodeteaser_update_1() { |
function nodeteaser_update_1() { |
| 59 |
return _system_update_utf8(array('nodeteaser')); |
return _system_update_utf8(array('nodeteaser')); |
| 60 |
} |
} |
|
?> |
|
| 61 |
|
|
| 62 |
|
|
| 63 |
|
/** |
| 64 |
|
* Implementation of hook_update_N(). Updates the system table to increase |
| 65 |
|
* the weight of Node Teaser. |
| 66 |
|
* |
| 67 |
|
* @todo Verify pgsql behavior. |
| 68 |
|
*/ |
| 69 |
|
function nodeteaser_update_2() { |
| 70 |
|
$result = array(); |
| 71 |
|
$result[] = update_sql("UPDATE {system} SET weight=99 WHERE name='nodeteaser';"); |
| 72 |
|
|
| 73 |
|
return $result; |
| 74 |
|
} |
| 75 |
|
|
| 76 |
|
|
| 77 |
|
/** |
| 78 |
|
* Implementation of hook_uninstall(). |
| 79 |
|
* |
| 80 |
|
* @todo Verify pgsql uninstall. |
| 81 |
|
*/ |
| 82 |
|
function nodeteaser_uninstall() { |
| 83 |
|
$success = false; |
| 84 |
|
|
| 85 |
|
switch ($GLOBALS['db_type']) { |
| 86 |
|
case 'mysql': |
| 87 |
|
case 'mysqli': |
| 88 |
|
$success = db_query('DROP TABLE IF EXISTS {nodeteaser};'); |
| 89 |
|
break; |
| 90 |
|
case 'pgsql': |
| 91 |
|
$success = db_query("DROP TABLE IF EXISTS {nodeteaser};"); |
| 92 |
|
break; |
| 93 |
|
} |
| 94 |
|
|
| 95 |
|
if ($success !== FALSE) { |
| 96 |
|
drupal_set_message(t('Node Teaser was uninstalled successfully.')); |
| 97 |
|
} |
| 98 |
|
else { |
| 99 |
|
drupal_set_message(t('Node Teaser could not be uninstalled.')); |
| 100 |
|
} |
| 101 |
|
} |