/[drupal]/contributions/modules/ec_live_subproducts/ec_live_subproducts.install
ViewVC logotype

Diff of /contributions/modules/ec_live_subproducts/ec_live_subproducts.install

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1 by brmassa, Wed Nov 15 00:46:54 2006 UTC revision 1.2 by brmassa, Wed Aug 1 14:42:19 2007 UTC
# Line 0  Line 1 
1    <?php
2    // $Id: ec_live_subproducts.install,v 1.1.1.2.2.4.2.4 2007/06/14 02:56:19 brmassa Exp $
3    /*******************************************************************************
4                         D R U P A L    M O D U L E
5    ********************************************************************************
6    Module Name        : E-Commerce Live Subproducts
7    Original Author    : Bruno Massa http://drupal.org/user/67164
8    Project Page       : http://drupal.org/project/ec_live_subproducts
9    Support Queue      : http://drupal.org/project/issues/ec_live_subproducts
10    
11    *******************************************************************************/
12    /**
13     * @file ec_live_subproducts.install
14     * Install and uninstall all required databases.
15     *
16     * Install and uninstall all required databases.
17     * Also do incremental database updates.
18     * Currently only works with MySQL
19     */
20    
21    /**
22     * EC Live Subproducts module schema
23     */
24    function ec_live_subproducts_install() {
25      $table_config = "";
26      switch ($GLOBALS["db_type"]) {
27        case "mysql":
28        case "mysqli":
29          $table_config = " TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */";
30        case "pgsql":
31          db_query("CREATE TABLE {ec_ls_attribute} (
32            nid                 INTEGER       PRIMARY KEY,
33            sku                 VARCHAR(255),
34            category            VARCHAR(50),
35            forbidden           VARCHAR(50),
36            stock               SMALLINT      NOT NULL,
37            pricevariation      DECIMAL(10,2) NOT NULL,
38            attr_weight         SMALLINT      NOT NULL
39            )". $table_config);
40          db_query("CREATE TABLE {ec_ls_bpattribute} (
41            pnid                INTEGER       NOT NULL,
42            nid                 INTEGER       NOT NULL
43            )". $table_config);
44          db_query("CREATE TABLE {ec_ls_pproduct} (
45            nid                 INTEGER       NOT NULL,
46            sku_title           BOOLEAN                DEFAULT 0,
47            children_creation   VARCHAR(50),
48            default_selection   VARCHAR(50)
49            )". $table_config);
50          db_query("CREATE TABLE {ec_ls_pattribute} (
51            pnid                INTEGER       NOT NULL,
52            nid                 INTEGER       NOT NULL
53            )". $table_config);
54          db_query("CREATE TABLE {ec_ls_variation} (
55            tid                 INTEGER       PRIMARY KEY,
56            listtype            SMALLINT      NOT NULL,
57            showprice           BOOLEAN       NOT NULL
58            )". $table_config);
59          db_query("ALTER TABLE {ec_ls_bpattribute} ADD FOREIGN KEY (pnid) REFERENCES {node}(nid)");
60          db_query("ALTER TABLE {ec_ls_bpattribute} ADD FOREIGN KEY (nid) REFERENCES {ec_ls_attribute}(nid)");
61          db_query("ALTER TABLE {ec_ls_pattribute}  ADD FOREIGN KEY (pnid) REFERENCES {node}(nid)");
62          db_query("ALTER TABLE {ec_ls_pattribute}  ADD FOREIGN KEY (nid) REFERENCES {ec_ls_attribute}(nid)");
63          db_query("ALTER TABLE {ec_ls_pproduct}    ADD FOREIGN KEY (nid) REFERENCES {node}(nid)");
64          db_query("UPDATE {system} SET weight=1 WHERE name='ec_live_subproducts'");
65          break;
66        case "default":
67          drupal_set_message(t("Your database is not supported"));
68      }
69      if (!empty($sucess)) {
70        drupal_set_message(t("EC Live Subproducts databases installed"));
71      }
72      $form["name"]         = t("EC Live Subproducts") .": ". t("Product Variation");
73      $form["description"]  = t("Each attribute much be on a variation.");
74      $form["help"]         = t("Each attribute much be on a variation.");
75      $form["nodes"]        = array("ec_live_subproducts_attribute" => "ec_live_subproducts_attribute");
76      $form["hierarchy"]    = 0;
77      $form["relations"]    = 0;
78      $form["tags"]         = FALSE;
79      $form["multiple"]     = 0;
80      $form["required"]     = TRUE;
81      $form["weight"]       = -5;
82      drupal_execute("taxonomy_form_vocabulary", $form);
83      $form["name"]         = t("EC Live Subproducts") .": ". t("Attribute Combination Categories");
84      $form["description"]  = t("Enter all attribute's categories. (Only necessary if you want to restrict combinations with this attribute)");
85      $form["help"]         = t("Enter all attribute's categories. (Only necessary if you want to restrict combinations with this attribute)");
86      $form["nodes"]        = array("ec_live_subproducts_attribute" => "ec_live_subproducts_attribute");
87      $form["hierarchy"]    = 0;
88      $form["relations"]    = 0;
89      $form["tags"]         = TRUE;
90      $form["multiple"]     = TRUE;
91      $form["required"]     = 0;
92      $form["weight"]       = 2;
93      drupal_execute("taxonomy_form_vocabulary", $form);
94      $form["name"]         = t("EC Live Subproducts") .": ". t("Attribute Forbidden Categories");
95      $form["description"]  = t("If you want to forbid this attribute to combine with another attribute (ie Wings and Cars), enter the attribute's category");
96      $form["help"]         = t("If you want to forbid this attribute to combine with another attribute (ie Wings and Cars), enter the attribute's category");
97      $form["nodes"]        = array("ec_live_subproducts_attribute" => "ec_live_subproducts_attribute");
98      $form["hierarchy"]    = 0;
99      $form["relations"]    = 0;
100      $form["tags"]         = TRUE;
101      $form["multiple"]     = 0;
102      $form["required"]     = 0;
103      $form["weight"]       = 3;
104      drupal_execute("taxonomy_form_vocabulary", $form);
105      $vid = db_fetch_array(db_query("SELECT MAX(vid) FROM {vocabulary}"));
106      variable_set("ec_live_subproducts_variation_vid", $vid["MAX(vid)"] - 2);
107      variable_set("ec_live_subproducts_combination_cat", $vid["MAX(vid)"] - 1);
108      variable_set("ec_live_subproducts_combination_forbid", $vid["MAX(vid)"]);
109    } // ec_live_subproducts_install()
110    
111    /**
112     * Uninstall all databases and delete variables
113     */
114    function ec_live_subproducts_uninstall() {
115      taxonomy_del_vocabulary(variable_set("ec_live_subproducts_combination_forbid", 0));
116      taxonomy_del_vocabulary(variable_set("ec_live_subproducts_combination_cat", 0));
117      taxonomy_del_vocabulary(variable_set("ec_live_subproducts_variation_vid", 0));
118      variable_del("ec_live_subproducts_combination_forbid");
119      variable_del("ec_live_subproducts_combination_cat");
120      variable_del("ec_live_subproducts_variation_vid");
121      node_type_delete($subproducts_types);
122      if (db_table_exists("ec_live_subproducts_variation"))             {db_query("DROP TABLE {ec_live_subproducts_variation}");}
123      if (db_table_exists("ec_live_subproducts_attribute"))             {db_query("DROP TABLE {ec_live_subproducts_attribute}");}
124      if (db_table_exists("ec_live_subproducts_product_attribute"))     {db_query("DROP TABLE {ec_live_subproducts_product_attribute}");}
125      if (db_table_exists("ec_live_subproducts_baseproduct_attribute")) {db_query("DROP TABLE {ec_live_subproducts_baseproduct_attribute}");}
126      if (db_table_exists("ec_live_subproducts_pproduct"))              {db_query("DROP TABLE {ec_live_subproducts_pproduct}");}
127      if (db_table_exists("ec_ls_attribute"))   {db_query("DROP TABLE {ec_ls_attribute}");}
128      if (db_table_exists("ec_ls_bpattribute")) {db_query("DROP TABLE {ec_ls_bpattribute}");}
129      if (db_table_exists("ec_ls_pproduct"))    {db_query("DROP TABLE {ec_ls_pproduct}");}
130      if (db_table_exists("ec_ls_pattribute"))  {db_query("DROP TABLE {ec_ls_pattribute}");}
131      if (db_table_exists("ec_ls_variation"))   {db_query("DROP TABLE {ec_ls_variation}");}
132    } // ec_live_subproducts_uninstall()
133    
134    function ec_live_subproducts_update_3() {
135      $messages = array();
136      switch ($GLOBALS["db_type"]) {
137        case "mysql":
138        case "mysqli":
139          if (variable_set("ec_live_subproducts_combination_forbid", 0) == 0) {
140            $form["name"]         = t("EC Live Subproducts") .":". t("Product Variation");
141            $form["description"]  = t("Each attribute much be on a variation.");
142            $form["help"]         = t("Each attribute much be on a variation.");
143            $form["nodes"]        = array("ec_live_subproducts_attribute" => "ec_live_subproducts_attribute");
144            $form["hierarchy"]    = 0;
145            $form["relations"]    = 0;
146            $form["tags"]         = 0;
147            $form["multiple"]     = 0;
148            $form["required"]     = 1;
149            $form["weight"]       = 0;
150            drupal_execute("taxonomy_form_vocabulary", $form);
151            $form["name"]         = t("EC Live Subproducts") .":". t("Attribute Combination Categories");
152            $form["description"]  = t("Enter all attribute's categories. (Only necessary if you want to restrict combinations with this attribute)");
153            $form["help"]         = t("Enter all attribute's categories. (Only necessary if you want to restrict combinations with this attribute)");
154            $form["nodes"]        = array("ec_live_subproducts_attribute" => "ec_live_subproducts_attribute");
155            $form["hierarchy"]    = 0;
156            $form["relations"]    = 0;
157            $form["tags"]         = 1;
158            $form["multiple"]     = 0;
159            $form["required"]     = 0;
160            $form["weight"]       = 0;
161            drupal_execute("taxonomy_form_vocabulary", $form);
162            $form["name"]         = t("EC Live Subproducts") .":". t("Attribute Forbidden Categories");
163            $form["description"]  = t("If you want to forbid this attribute to combine with another attribute (ie Wings and Cars), enter the attribute's category");
164            $form["help"]         = t("If you want to forbid this attribute to combine with another attribute (ie Wings and Cars), enter the attribute's category");
165            $form["nodes"]        = array("ec_live_subproducts_attribute" => "ec_live_subproducts_attribute");
166            $form["hierarchy"]    = 0;
167            $form["relations"]    = 0;
168            $form["tags"]         = 1;
169            $form["multiple"]     = 0;
170            $form["required"]     = 0;
171            $form["weight"]       = 0;
172            drupal_execute("taxonomy_form_vocabulary", $form);
173            $vid = db_fetch_array(db_query("SELECT MAX(vid) FROM {vocabulary}"));
174            variable_set("ec_live_subproducts_variation_vid", $vid["MAX(vid)"] - 2);
175            variable_set("ec_live_subproducts_combination_cat", $vid["MAX(vid)"] - 1);
176            variable_set("ec_live_subproducts_combination_forbid", $vid["MAX(vid)"]);
177          }
178          break;
179        default:
180      }
181      return $messages;
182    } // ec_live_subproducts_update_3
183    
184    function ec_live_subproducts_update_4() {
185      $items = array();
186      switch ($GLOBALS["db_type"]) {
187        case "mysql":
188        case "mysqli":
189          $items[] = update_sql("ALTER TABLE {ec_live_subproducts_attribute} ADD attr_weight TINYINT NOT NULL DEFAULT 0");
190        break;
191      }
192      return $items;
193    } // ec_live_subproducts_update_4()
194    
195    function ec_live_subproducts_update_5() {
196      $updates = array();
197      $updates[] = update_sql("RENAME TABLE {ec_live_subproducts_attribute}              TO {ec_ls_attribute}");
198      $updates[] = update_sql("RENAME TABLE {ec_live_subproducts_baseproduct_attribute}  TO {ec_ls_bpattribute}");
199      $updates[] = update_sql("RENAME TABLE {ec_live_subproducts_product_attribute}      TO {ec_ls_pattribute}");
200      $updates[] = update_sql("RENAME TABLE {ec_live_subproducts_pproduct}               TO {ec_ls_pproduct}");
201      $updates[] = update_sql("RENAME TABLE {ec_live_subproducts_variation}              TO {ec_ls_variation}");
202    
203      $updates[] = update_sql("ALTER TABLE {ec_ls_bpattribute} DROP INDEX nid");
204      $updates[] = update_sql("ALTER TABLE {ec_ls_bpattribute} DROP INDEX pnid");
205      $updates[] = update_sql("ALTER TABLE {ec_ls_pattribute}  DROP INDEX nid");
206      $updates[] = update_sql("ALTER TABLE {ec_ls_pattribute}  DROP INDEX pnid");
207      $updates[] = update_sql("ALTER TABLE {ec_ls_pproduct}   DROP INDEX nid");
208      $updates[] = update_sql("ALTER TABLE {ec_ls_attribute}  DROP PRIMARY KEY");
209      $updates[] = update_sql("ALTER TABLE {ec_ls_variation}  DROP PRIMARY KEY");
210    
211      $updates[] = update_sql("ALTER TABLE {ec_ls_attribute} CHANGE nid nid INTEGER PRIMARY KEY");
212      $updates[] = update_sql("ALTER TABLE {ec_ls_attribute} CHANGE sku sku VARCHAR(255)");
213      $updates[] = update_sql("ALTER TABLE {ec_ls_attribute} CHANGE category category VARCHAR(50)");
214      $updates[] = update_sql("ALTER TABLE {ec_ls_attribute} CHANGE forbidden forbidden VARCHAR(50)");
215      $updates[] = update_sql("ALTER TABLE {ec_ls_attribute} CHANGE stock stock SMALLINT NOT NULL");
216      $updates[] = update_sql("ALTER TABLE {ec_ls_attribute} CHANGE pricevariation pricevariation DECIMAL(10,2) NOT NULL");
217      $updates[] = update_sql("ALTER TABLE {ec_ls_attribute} CHANGE attr_weight attr_weight SMALLINT NOT NULL");
218      $updates[] = update_sql("ALTER TABLE {ec_ls_bpattribute} CHANGE pnid pnid INTEGER NOT NULL");
219      $updates[] = update_sql("ALTER TABLE {ec_ls_bpattribute} CHANGE nid nid INTEGER NOT NULL");
220      $updates[] = update_sql("ALTER TABLE {ec_ls_pattribute}  CHANGE pnid pnid INTEGER NOT NULL");
221      $updates[] = update_sql("ALTER TABLE {ec_ls_pattribute}  CHANGE nid nid INTEGER NOT NULL");
222      $updates[] = update_sql("ALTER TABLE {ec_ls_pproduct} CHANGE nid nid INTEGER NOT NULL");
223      $updates[] = update_sql("ALTER TABLE {ec_ls_pproduct} CHANGE sku_title sku_title BOOLEAN DEFAULT 0");
224      $updates[] = update_sql("ALTER TABLE {ec_ls_pproduct} CHANGE children_creation children_creation VARCHAR(50)");
225      $updates[] = update_sql("ALTER TABLE {ec_ls_pproduct} CHANGE default_selection default_selection VARCHAR(50)");
226      $updates[] = update_sql("ALTER TABLE {ec_ls_variation} CHANGE tid tid INTEGER PRIMARY KEY");
227      $updates[] = update_sql("ALTER TABLE {ec_ls_variation} CHANGE listtype listtype SMALLINT NOT NULL");
228      $updates[] = update_sql("ALTER TABLE {ec_ls_variation} CHANGE showprice showprice BOOLEAN NOT NULL");
229    
230      $updates[] = update_sql("ALTER TABLE {ec_ls_bpattribute} ADD FOREIGN KEY (pnid) REFERENCES {node}(nid)");
231      $updates[] = update_sql("ALTER TABLE {ec_ls_bpattribute} ADD FOREIGN KEY (nid) REFERENCES {ec_ls_attribute}(nid)");
232      $updates[] = update_sql("ALTER TABLE {ec_ls_pattribute}  ADD FOREIGN KEY (pnid) REFERENCES {node}(nid)");
233      $updates[] = update_sql("ALTER TABLE {ec_ls_pattribute}  ADD FOREIGN KEY (nid) REFERENCES {ec_ls_attribute}(nid)");
234      $updates[] = update_sql("ALTER TABLE {ec_ls_pproduct}    ADD FOREIGN KEY (nid) REFERENCES {node}(nid)");
235      return $updates;
236    } // ec_live_subproducts_update_5()
237    
238    /**
239     * Fix an old issue that the variations should be not threated as tags
240     */
241    function ec_live_subproducts_update_6() {
242      $updates = array();
243      array_push($updates, update_sql("UPDATE {vocabulary} SET tags = 0 WHERE vid = ". variable_get("ec_live_subproducts_variation_vid", NULL)));
244      return $updates;
245    } // end of ec_live_subproducts_update_6()

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.3