PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/app/code/core/Mage/ProductAlert/sql/productalert_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php

https://gitlab.com/blingbang2016/shop
PHP | 321 lines | 249 code | 32 blank | 40 comment | 0 complexity | 746880502eae6875f53f55caf018d77b MD5 | raw file
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magento.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magento.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_ProductAlert
  23. * @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /* @var $installer Mage_Core_Model_Resource_Setup */
  27. $installer = $this;
  28. $installer->startSetup();
  29. /**
  30. * Drop foreign keys
  31. */
  32. $installer->getConnection()->dropForeignKey(
  33. $installer->getTable('productalert/price'),
  34. 'FK_PRODUCT_ALERT_PRICE_CUSTOMER'
  35. );
  36. $installer->getConnection()->dropForeignKey(
  37. $installer->getTable('productalert/price'),
  38. 'FK_PRODUCT_ALERT_PRICE_PRODUCT'
  39. );
  40. $installer->getConnection()->dropForeignKey(
  41. $installer->getTable('productalert/price'),
  42. 'FK_PRODUCT_ALERT_PRICE_WEBSITE'
  43. );
  44. $installer->getConnection()->dropForeignKey(
  45. $installer->getTable('productalert/stock'),
  46. 'FK_PRODUCT_ALERT_STOCK_CUSTOMER'
  47. );
  48. $installer->getConnection()->dropForeignKey(
  49. $installer->getTable('productalert/stock'),
  50. 'FK_PRODUCT_ALERT_STOCK_PRODUCT'
  51. );
  52. $installer->getConnection()->dropForeignKey(
  53. $installer->getTable('productalert/stock'),
  54. 'FK_PRODUCT_ALERT_STOCK_WEBSITE'
  55. );
  56. /**
  57. * Drop indexes
  58. */
  59. $installer->getConnection()->dropIndex(
  60. $installer->getTable('productalert/price'),
  61. 'FK_PRODUCT_ALERT_PRICE_CUSTOMER'
  62. );
  63. $installer->getConnection()->dropIndex(
  64. $installer->getTable('productalert/price'),
  65. 'FK_PRODUCT_ALERT_PRICE_PRODUCT'
  66. );
  67. $installer->getConnection()->dropIndex(
  68. $installer->getTable('productalert/price'),
  69. 'FK_PRODUCT_ALERT_PRICE_WEBSITE'
  70. );
  71. $installer->getConnection()->dropIndex(
  72. $installer->getTable('productalert/stock'),
  73. 'FK_PRODUCT_ALERT_STOCK_CUSTOMER'
  74. );
  75. $installer->getConnection()->dropIndex(
  76. $installer->getTable('productalert/stock'),
  77. 'FK_PRODUCT_ALERT_STOCK_PRODUCT'
  78. );
  79. $installer->getConnection()->dropIndex(
  80. $installer->getTable('productalert/stock'),
  81. 'FK_PRODUCT_ALERT_STOCK_WEBSITE'
  82. );
  83. /**
  84. * Change columns
  85. */
  86. $tables = array(
  87. $installer->getTable('productalert/price') => array(
  88. 'columns' => array(
  89. 'alert_price_id' => array(
  90. 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
  91. 'identity' => true,
  92. 'unsigned' => true,
  93. 'nullable' => false,
  94. 'primary' => true,
  95. 'comment' => 'Product alert price id'
  96. ),
  97. 'customer_id' => array(
  98. 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
  99. 'unsigned' => true,
  100. 'nullable' => false,
  101. 'default' => '0',
  102. 'comment' => 'Customer id'
  103. ),
  104. 'product_id' => array(
  105. 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
  106. 'unsigned' => true,
  107. 'nullable' => false,
  108. 'default' => '0',
  109. 'comment' => 'Product id'
  110. ),
  111. 'price' => array(
  112. 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL,
  113. 'scale' => 4,
  114. 'precision' => 12,
  115. 'nullable' => false,
  116. 'default' => '0.0000',
  117. 'comment' => 'Price amount'
  118. ),
  119. 'website_id' => array(
  120. 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
  121. 'unsigned' => true,
  122. 'nullable' => false,
  123. 'default' => '0',
  124. 'comment' => 'Website id'
  125. ),
  126. 'add_date' => array(
  127. 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP,
  128. 'nullable' => false,
  129. 'comment' => 'Product alert add date'
  130. ),
  131. 'last_send_date' => array(
  132. 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP,
  133. 'comment' => 'Product alert last send date'
  134. ),
  135. 'send_count' => array(
  136. 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
  137. 'unsigned' => true,
  138. 'nullable' => false,
  139. 'default' => '0',
  140. 'comment' => 'Product alert send count'
  141. ),
  142. 'status' => array(
  143. 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
  144. 'unsigned' => true,
  145. 'nullable' => false,
  146. 'default' => '0',
  147. 'comment' => 'Product alert status'
  148. )
  149. ),
  150. 'comment' => 'Product Alert Price'
  151. ),
  152. $installer->getTable('productalert/stock') => array(
  153. 'columns' => array(
  154. 'alert_stock_id' => array(
  155. 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
  156. 'identity' => true,
  157. 'unsigned' => true,
  158. 'nullable' => false,
  159. 'primary' => true,
  160. 'comment' => 'Product alert stock id'
  161. ),
  162. 'customer_id' => array(
  163. 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
  164. 'unsigned' => true,
  165. 'nullable' => false,
  166. 'default' => '0',
  167. 'comment' => 'Customer id'
  168. ),
  169. 'product_id' => array(
  170. 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
  171. 'unsigned' => true,
  172. 'nullable' => false,
  173. 'default' => '0',
  174. 'comment' => 'Product id'
  175. ),
  176. 'website_id' => array(
  177. 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
  178. 'unsigned' => true,
  179. 'nullable' => false,
  180. 'default' => '0',
  181. 'comment' => 'Website id'
  182. ),
  183. 'add_date' => array(
  184. 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP,
  185. 'nullable' => false,
  186. 'comment' => 'Product alert add date'
  187. ),
  188. 'send_date' => array(
  189. 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP,
  190. 'comment' => 'Product alert send date'
  191. ),
  192. 'send_count' => array(
  193. 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
  194. 'unsigned' => true,
  195. 'nullable' => false,
  196. 'default' => '0',
  197. 'comment' => 'Send Count'
  198. ),
  199. 'status' => array(
  200. 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
  201. 'unsigned' => true,
  202. 'nullable' => false,
  203. 'default' => '0',
  204. 'comment' => 'Product alert status'
  205. )
  206. ),
  207. 'comment' => 'Product Alert Stock'
  208. )
  209. );
  210. $installer->getConnection()->modifyTables($tables);
  211. /**
  212. * Add indexes
  213. */
  214. $installer->getConnection()->addIndex(
  215. $installer->getTable('productalert/price'),
  216. $installer->getIdxName('productalert/price', array('customer_id')),
  217. array('customer_id')
  218. );
  219. $installer->getConnection()->addIndex(
  220. $installer->getTable('productalert/price'),
  221. $installer->getIdxName('productalert/price', array('product_id')),
  222. array('product_id')
  223. );
  224. $installer->getConnection()->addIndex(
  225. $installer->getTable('productalert/price'),
  226. $installer->getIdxName('productalert/price', array('website_id')),
  227. array('website_id')
  228. );
  229. $installer->getConnection()->addIndex(
  230. $installer->getTable('productalert/stock'),
  231. $installer->getIdxName('productalert/stock', array('customer_id')),
  232. array('customer_id')
  233. );
  234. $installer->getConnection()->addIndex(
  235. $installer->getTable('productalert/stock'),
  236. $installer->getIdxName('productalert/stock', array('product_id')),
  237. array('product_id')
  238. );
  239. $installer->getConnection()->addIndex(
  240. $installer->getTable('productalert/stock'),
  241. $installer->getIdxName('productalert/stock', array('website_id')),
  242. array('website_id')
  243. );
  244. /**
  245. * Add foreign keys
  246. */
  247. $installer->getConnection()->addForeignKey(
  248. $installer->getFkName('productalert/price', 'customer_id', 'customer/entity', 'entity_id'),
  249. $installer->getTable('productalert/price'),
  250. 'customer_id',
  251. $installer->getTable('customer/entity'),
  252. 'entity_id'
  253. );
  254. $installer->getConnection()->addForeignKey(
  255. $installer->getFkName('productalert/price', 'product_id', 'catalog/product', 'entity_id'),
  256. $installer->getTable('productalert/price'),
  257. 'product_id',
  258. $installer->getTable('catalog/product'),
  259. 'entity_id'
  260. );
  261. $installer->getConnection()->addForeignKey(
  262. $installer->getFkName('productalert/price', 'website_id', 'core/website', 'website_id'),
  263. $installer->getTable('productalert/price'),
  264. 'website_id',
  265. $installer->getTable('core/website'),
  266. 'website_id'
  267. );
  268. $installer->getConnection()->addForeignKey(
  269. $installer->getFkName('productalert/stock', 'website_id', 'core/website', 'website_id'),
  270. $installer->getTable('productalert/stock'),
  271. 'website_id',
  272. $installer->getTable('core/website'),
  273. 'website_id'
  274. );
  275. $installer->getConnection()->addForeignKey(
  276. $installer->getFkName('productalert/stock', 'customer_id', 'customer/entity', 'entity_id'),
  277. $installer->getTable('productalert/stock'),
  278. 'customer_id',
  279. $installer->getTable('customer/entity'),
  280. 'entity_id'
  281. );
  282. $installer->getConnection()->addForeignKey(
  283. $installer->getFkName('productalert/stock', 'product_id', 'catalog/product', 'entity_id'),
  284. $installer->getTable('productalert/stock'),
  285. 'product_id',
  286. $installer->getTable('catalog/product'),
  287. 'entity_id'
  288. );
  289. $installer->endSetup();