| 1 |
<?php |
<?php |
| 2 |
// recipe.install |
function recipe_schema() { |
| 3 |
function recipe_install() { |
$schema['recipe'] = array( |
| 4 |
$s = false; |
'fields' => array( |
| 5 |
switch ($GLOBALS['db_type']) { |
'nid' => array( |
| 6 |
case 'mysql': |
'description' => t('The primary identifier for a recipe.'), |
| 7 |
case 'mysqli': |
'type' => 'serial', |
| 8 |
$s = db_query("CREATE TABLE {recipe} ( |
'unsigned' => TRUE, |
| 9 |
nid int(10) unsigned NOT NULL, |
'not null' => TRUE), |
| 10 |
source varchar(255), |
'source' => array( |
| 11 |
yield int(2) unsigned NOT NULL, |
'type' => 'varchar', |
| 12 |
instructions text, |
'not null' => FALSE, |
| 13 |
notes text, |
'length' => 255), |
| 14 |
preptime int(10) unsigned DEFAULT '0', |
'yield' => array( |
| 15 |
PRIMARY KEY (nid) |
'type' => 'int', |
| 16 |
) /*!40100 DEFAULT CHARACTER SET utf8 */;"); |
'unsigned' => FALSE, |
| 17 |
|
'not null' => TRUE), |
| 18 |
$s = $s && db_query("CREATE TABLE {recipe_node_ingredient} ( |
'instructions' => array( |
| 19 |
id int unsigned NOT NULL PRIMARY KEY auto_increment, |
'type' => 'text'), |
| 20 |
nid int(10) unsigned NOT NULL, |
'notes' => array( |
| 21 |
unit_id int(3) unsigned NOT NULL, |
'type' => 'text'), |
| 22 |
quantity double, |
'preptime' => array( |
| 23 |
ingredient_id int(10) unsigned NOT NULL |
'type' => 'int', |
| 24 |
) /*!40100 DEFAULT CHARACTER SET utf8 */;"); |
'unsigned' => TRUE, |
| 25 |
|
'default' => 0), |
| 26 |
$s = $s && db_query("CREATE TABLE {recipe_ingredient} ( |
), |
| 27 |
id int(10) unsigned NOT NULL PRIMARY KEY auto_increment, |
'primary key' => array('nid'), |
| 28 |
name varchar(255), |
); |
| 29 |
link int(10) NOT NULL |
$schema['recipe_node_ingredient'] = array( |
| 30 |
) /*!40100 DEFAULT CHARACTER SET utf8 */;"); |
'description' => t('The base table for recipe ingredients.'), |
| 31 |
|
'fields' => array( |
| 32 |
$s = $s && db_query("CREATE TABLE {recipe_unit} ( |
'id' => array( |
| 33 |
id int(3) unsigned NOT NULL PRIMARY KEY auto_increment, |
'description' => t('The primary identifier for a recipe ingredient.'), |
| 34 |
name varchar(64) NOT NULL default '', |
'type' => 'serial', |
| 35 |
abbreviation varchar(8) NOT NULL default '', |
'unsigned' => TRUE, |
| 36 |
metric int(1) unsigned NOT NULL default '0', |
'not null' => TRUE), |
| 37 |
type enum('Mass','Volume','Unit') NOT NULL default 'Mass' |
'nid' => array( |
| 38 |
) /*!40100 DEFAULT CHARACTER SET utf8 */;"); |
'type' => 'int', |
| 39 |
|
'unsigned' => TRUE, |
| 40 |
$s = $s && recipe_populate_units(); |
'not null' => TRUE), |
| 41 |
break; |
'unit_id' => array( |
| 42 |
|
'type' => 'int', |
| 43 |
case 'pgsql': |
'unsigned' => TRUE, |
| 44 |
$s = db_query("CREATE TABLE {recipe} ( |
'not null' => TRUE), |
| 45 |
nid integer NOT NULL, |
'quantity' => array( |
| 46 |
source varchar(255), |
'type' => 'float', |
| 47 |
yield integer NOT NULL, |
'not null' => FALSE), |
| 48 |
instructions text, |
'ingredient_id' => array( |
| 49 |
notes text, |
'type' => 'int', |
| 50 |
preptime integer NOT NULL default '0', |
'unsigned' => TRUE, |
| 51 |
PRIMARY KEY (nid) |
'not null' => TRUE), |
| 52 |
);"); |
), |
| 53 |
|
'primary key' => array('id'), |
| 54 |
$s = $s && db_query("CREATE TABLE {recipe_node_ingredient} ( |
); |
| 55 |
id serial NOT NULL, |
$schema['recipe_ingredient'] = array( |
| 56 |
nid integer NOT NULL, |
'description' => t('The base table for recipe ingredients.'), |
| 57 |
unit_id integer NOT NULL, |
'fields' => array( |
| 58 |
quantity real, |
'id' => array( |
| 59 |
ingredient_id integer NOT NULL, |
'description' => t('The primary identifier for a recipe ingredient.'), |
| 60 |
PRIMARY KEY(id) |
'type' => 'serial', |
| 61 |
);"); |
'unsigned' => TRUE, |
| 62 |
|
'not null' => TRUE), |
| 63 |
$s = $s && db_query("CREATE TABLE {recipe_ingredient} ( |
'name' => array( |
| 64 |
id serial NOT NULL PRIMARY KEY, |
'type' => 'varchar', |
| 65 |
name varchar(255), |
'length' => 255), |
| 66 |
link integer NOT NULL |
'link' => array( |
| 67 |
);"); |
'type' => 'int', |
| 68 |
|
'unsigned' => TRUE, |
| 69 |
$s = $s && db_query("CREATE TABLE {recipe_unit} ( |
'not null' => TRUE), |
| 70 |
id serial NOT NULL PRIMARY KEY, |
), |
| 71 |
name varchar(64) NOT NULL default '', |
'primary key' => array('id'), |
| 72 |
abbreviation varchar(8) NOT NULL default '', |
); |
| 73 |
metric integer NOT NULL default '0', |
$schema['recipe_unit'] = array( |
| 74 |
type varchar(6) NOT NULL default 'Mass' |
'description' => t('The base table for recipe units.'), |
| 75 |
);"); |
'fields' => array( |
| 76 |
|
'id' => array( |
| 77 |
$s = $s && recipe_populate_units(); |
'type' => 'serial', |
| 78 |
break; |
'unsigned' => TRUE, |
| 79 |
} |
'not null' => TRUE), |
| 80 |
if ($s) { |
'name' => array( |
| 81 |
drupal_set_message(t('Recipe module installed tables successfully.')); |
'type' => 'varchar', |
| 82 |
} |
'length' => 255), |
| 83 |
else { |
'abbreviation' => array( |
| 84 |
drupal_set_message(t('The installation of the Recipe module was unsuccessful.'), 'error'); |
'type' => 'varchar', |
| 85 |
} |
'length' => 8), |
| 86 |
} |
'metric' => array( |
| 87 |
|
'type' => 'int', |
| 88 |
function recipe_update_1() { |
'not null' => TRUE, |
| 89 |
$ret = array(); |
'unsigned' => TRUE, |
| 90 |
$ret[] = update_sql("ALTER TABLE {recipe_node_ingredient} DROP weight"); |
'default' => 0), |
| 91 |
switch ($GLOBALS['db_type']) { |
'type' => array( |
| 92 |
case 'pgsql': |
'type' => 'varchar', |
| 93 |
db_add_column($ret, 'recipe', 'preptime', 'integer', array('not null' => TRUE, 'default' => 0)); |
'length' => 6, |
| 94 |
break; |
'not null' => TRUE, |
| 95 |
|
'default' => 'Mass'), |
| 96 |
case 'mysql': |
), |
| 97 |
case 'mysqli': |
'primary key' => array('id'), |
| 98 |
$ret[] = update_sql("ALTER TABLE {recipe} ADD COLUMN preptime int(10) NOT NULL DEFAULT 0"); |
); |
| 99 |
break; |
|
| 100 |
} |
return $schema; |
| 101 |
return $ret; |
} |
| 102 |
} |
function recipe_install() { |
| 103 |
|
drupal_install_schema('recipe'); |
| 104 |
/** |
recipe_populate_units(); |
| 105 |
* Adds a field to link ingredient to corresponding node. |
} |
| 106 |
*/ |
|
| 107 |
function recipe_update_2() { |
function recipe_populate_units() { |
| 108 |
$ret = array(); |
$s = true; |
| 109 |
|
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (1, 'Slice', 'sli', 0, 'Unit');"); |
| 110 |
$ret[] = update_sql('ALTER TABLE {recipe_ingredient} ADD link INT NOT NULL'); |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (2, 'Unit', '', 0, 'Unit');"); |
| 111 |
|
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (3, 'Clove', 'clv', 0, 'Unit');"); |
| 112 |
return $ret; |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (4, 'Pinch', 'pn', 0, 'Unit');"); |
| 113 |
} |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (5, 'Package', 'pk', 0, 'Unit');"); |
| 114 |
|
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (6, 'Can', 'cn', 0, 'Unit');"); |
| 115 |
function recipe_populate_units() |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (7, 'Drop', 'dr', 0, 'Unit');"); |
| 116 |
{ |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (8, 'Bunch', 'bn', 0, 'Unit');"); |
| 117 |
$s = true; |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (9, 'Dash', 'ds', 0, 'Unit');"); |
| 118 |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (1, 'Slice', 'sli', 0, 'Unit');"); |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (10, 'Carton', 'ct', 0, 'Unit');"); |
| 119 |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (2, 'Unit', '', 0, 'Unit');"); |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (11, 'Cup', 'c', 0, 'Unit');"); |
| 120 |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (3, 'Clove', 'clv', 0, 'Unit');"); |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (12, 'Tablespoon', 'T', 0, 'Volume');"); |
| 121 |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (4, 'Pinch', 'pn', 0, 'Unit');"); |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (13, 'Teaspoon', 't', 0, 'Volume');"); |
| 122 |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (5, 'Package', 'pk', 0, 'Unit');"); |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (14, 'Pound', 'lb', 0, 'Mass');"); |
| 123 |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (6, 'Can', 'cn', 0, 'Unit');"); |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (15, 'Ounce', 'oz', 0, 'Mass');"); |
| 124 |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (7, 'Drop', 'dr', 0, 'Unit');"); |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (16, 'Pint', 'pt', 0, 'Volume');"); |
| 125 |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (8, 'Bunch', 'bn', 0, 'Unit');"); |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (17, 'Quart', 'q', 0, 'Volume');"); |
| 126 |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (9, 'Dash', 'ds', 0, 'Unit');"); |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (18, 'Gallon', 'gal', 0, 'Volume');"); |
| 127 |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (10, 'Carton', 'ct', 0, 'Unit');"); |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (19, 'Milligram', 'mg', 1, 'Mass');"); |
| 128 |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (11, 'Cup', 'c', 0, 'Unit');"); |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (20, 'Centigram', 'cg', 1, 'Mass');"); |
| 129 |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (12, 'Tablespoon', 'T', 0, 'Volume');"); |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (21, 'Gram', 'g', 1, 'Mass');"); |
| 130 |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (13, 'Teaspoon', 't', 0, 'Volume');"); |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (22, 'Kilogram', 'kg', 1, 'Mass');"); |
| 131 |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (14, 'Pound', 'lb', 0, 'Mass');"); |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (23, 'Millilitre', 'ml', 1, 'Volume');"); |
| 132 |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (15, 'Ounce', 'oz', 0, 'Mass');"); |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (24, 'Centilitre', 'cl', 1, 'Volume');"); |
| 133 |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (16, 'Pint', 'pt', 0, 'Volume');"); |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (25, 'Litre', 'l', 1, 'Volume');"); |
| 134 |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (17, 'Quart', 'q', 0, 'Volume');"); |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (26, 'Decilitre', 'dl', 1, 'Volume');"); |
| 135 |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (18, 'Gallon', 'gal', 0, 'Volume');"); |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (27, 'Tablespoon (Metric)', 'tbsp', 1, 'Volume');"); |
| 136 |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (19, 'Milligram', 'mg', 1, 'Mass');"); |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (28, 'Teaspoon (Metric)', 'tsp', 1, 'Volume');"); |
| 137 |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (20, 'Centigram', 'cg', 1, 'Mass');"); |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (29, 'Unknown', '', 0, 'Unit');"); |
| 138 |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (21, 'Gram', 'g', 1, 'Mass');"); |
return $s; |
| 139 |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (22, 'Kilogram', 'kg', 1, 'Mass');"); |
} |
| 140 |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (23, 'Millilitre', 'ml', 1, 'Volume');"); |
|
| 141 |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (24, 'Centilitre', 'cl', 1, 'Volume');"); |
function recipe_uninstall() { |
| 142 |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (25, 'Litre', 'l', 1, 'Volume');"); |
drupal_uninstall_schema('recipe'); |
| 143 |
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (26, 'Decilitre', 'dl', 1, 'Volume');"); |
} |
|
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (27, 'Tablespoon (Metric)', 'tbsp', 1, 'Volume');"); |
|
|
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (28, 'Teaspoon (Metric)', 'tsp', 1, 'Volume');"); |
|
|
$s = $s && db_query("INSERT INTO {recipe_unit} VALUES (29, 'Unknown', '', 0, 'Unit');"); |
|
|
return $s; |
|
|
} |
|
|
|
|
|
function recipe_uninstall() |
|
|
{ |
|
|
if (db_table_exists("recipe")) { |
|
|
db_query("DROP TABLE {recipe}"); |
|
|
} |
|
|
if (db_table_exists("recipe_node_ingredient")) { |
|
|
db_query("DROP TABLE {recipe_node_ingredient}"); |
|
|
} |
|
|
if (db_table_exists("recipe_ingredient")) { |
|
|
db_query("DROP TABLE {recipe_ingredient}"); |
|
|
} |
|
|
if (db_table_exists("recipe_unit")) { |
|
|
db_query("DROP TABLE {recipe_unit}"); |
|
|
} |
|
|
} |
|