PageRenderTime 55ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php

https://bitbucket.org/acidel/buykoala
PHP | 306 lines | 237 code | 29 blank | 40 comment | 0 complexity | eb6b0bc8c31a9f65ad54b889759da932 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@magentocommerce.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.magentocommerce.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Wishlist
  23. * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.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('wishlist/wishlist'),
  34. 'FK_WISHLIST_CUSTOMER'
  35. );
  36. $installer->getConnection()->dropForeignKey(
  37. $installer->getTable('wishlist/item'),
  38. 'FK_WISHLIST_ITEM_PRODUCT'
  39. );
  40. $installer->getConnection()->dropForeignKey(
  41. $installer->getTable('wishlist/item'),
  42. 'FK_WISHLIST_ITEM_STORE'
  43. );
  44. $installer->getConnection()->dropForeignKey(
  45. $installer->getTable('wishlist/item'),
  46. 'FK_WISHLIST_ITEM_WISHLIST'
  47. );
  48. $installer->getConnection()->dropForeignKey(
  49. $installer->getTable('wishlist/item_option'),
  50. 'FK_WISHLIST_ITEM_OPTION_ITEM_ID'
  51. );
  52. /**
  53. * Drop indexes
  54. */
  55. $installer->getConnection()->dropIndex(
  56. $installer->getTable('wishlist/wishlist'),
  57. 'UNQ_CUSTOMER'
  58. );
  59. $installer->getConnection()->dropIndex(
  60. $installer->getTable('wishlist/wishlist'),
  61. 'IDX_IS_SHARED'
  62. );
  63. $installer->getConnection()->dropIndex(
  64. $installer->getTable('wishlist/item'),
  65. 'IDX_WISHLIST'
  66. );
  67. $installer->getConnection()->dropIndex(
  68. $installer->getTable('wishlist/item'),
  69. 'IDX_PRODUCT'
  70. );
  71. $installer->getConnection()->dropIndex(
  72. $installer->getTable('wishlist/item'),
  73. 'IDX_STORE'
  74. );
  75. $installer->getConnection()->dropIndex(
  76. $installer->getTable('wishlist/item_option'),
  77. 'FK_WISHLIST_ITEM_OPTION_ITEM_ID'
  78. );
  79. /**
  80. * Change columns
  81. */
  82. $tables = array(
  83. $installer->getTable('wishlist/wishlist') => array(
  84. 'columns' => array(
  85. 'wishlist_id' => array(
  86. 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
  87. 'identity' => true,
  88. 'unsigned' => true,
  89. 'nullable' => false,
  90. 'primary' => true,
  91. 'comment' => 'Wishlist ID'
  92. ),
  93. 'customer_id' => array(
  94. 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
  95. 'unsigned' => true,
  96. 'nullable' => false,
  97. 'default' => '0',
  98. 'comment' => 'Customer ID'
  99. ),
  100. 'shared' => array(
  101. 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
  102. 'unsigned' => true,
  103. 'nullable' => false,
  104. 'default' => '0',
  105. 'comment' => 'Sharing flag (0 or 1)'
  106. ),
  107. 'sharing_code' => array(
  108. 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
  109. 'length' => 32,
  110. 'comment' => 'Sharing encrypted code'
  111. ),
  112. 'updated_at' => array(
  113. 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP,
  114. 'comment' => 'Last updated date'
  115. )
  116. ),
  117. 'comment' => 'Wishlist main Table'
  118. ),
  119. $installer->getTable('wishlist/item') => array(
  120. 'columns' => array(
  121. 'wishlist_item_id' => array(
  122. 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
  123. 'identity' => true,
  124. 'unsigned' => true,
  125. 'nullable' => false,
  126. 'primary' => true,
  127. 'comment' => 'Wishlist item ID'
  128. ),
  129. 'wishlist_id' => array(
  130. 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
  131. 'unsigned' => true,
  132. 'nullable' => false,
  133. 'default' => '0',
  134. 'comment' => 'Wishlist ID'
  135. ),
  136. 'product_id' => array(
  137. 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
  138. 'unsigned' => true,
  139. 'nullable' => false,
  140. 'default' => '0',
  141. 'comment' => 'Product ID'
  142. ),
  143. 'store_id' => array(
  144. 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
  145. 'unsigned' => true,
  146. 'comment' => 'Store ID'
  147. ),
  148. 'added_at' => array(
  149. 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP,
  150. 'comment' => 'Add date and time'
  151. ),
  152. 'description' => array(
  153. 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
  154. 'length' => '64K',
  155. 'comment' => 'Short description of wish list item'
  156. ),
  157. 'qty' => array(
  158. 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL,
  159. 'scale' => 4,
  160. 'precision' => 12,
  161. 'nullable' => false,
  162. 'comment' => 'Qty'
  163. )
  164. ),
  165. 'comment' => 'Wishlist items'
  166. ),
  167. $installer->getTable('wishlist/item_option') => array(
  168. 'columns' => array(
  169. 'option_id' => array(
  170. 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
  171. 'identity' => true,
  172. 'unsigned' => true,
  173. 'nullable' => false,
  174. 'primary' => true,
  175. 'comment' => 'Option Id'
  176. ),
  177. 'wishlist_item_id' => array(
  178. 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
  179. 'unsigned' => true,
  180. 'nullable' => false,
  181. 'comment' => 'Wishlist Item Id'
  182. ),
  183. 'product_id' => array(
  184. 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
  185. 'unsigned' => true,
  186. 'nullable' => false,
  187. 'comment' => 'Product Id'
  188. ),
  189. 'code' => array(
  190. 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
  191. 'length' => 255,
  192. 'nullable' => false,
  193. 'comment' => 'Code'
  194. ),
  195. 'value' => array(
  196. 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
  197. 'length' => '64K',
  198. 'nullable' => true,
  199. 'comment' => 'Value'
  200. )
  201. ),
  202. 'comment' => 'Wishlist Item Option Table'
  203. )
  204. );
  205. $installer->getConnection()->modifyTables($tables);
  206. /**
  207. * Add indexes
  208. */
  209. $installer->getConnection()->addIndex(
  210. $installer->getTable('wishlist/wishlist'),
  211. $installer->getIdxName(
  212. 'wishlist/wishlist',
  213. array('customer_id'),
  214. Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE),
  215. array('customer_id'),
  216. Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE
  217. );
  218. $installer->getConnection()->addIndex(
  219. $installer->getTable('wishlist/wishlist'),
  220. $installer->getIdxName('wishlist/wishlist', array('shared')),
  221. array('shared')
  222. );
  223. $installer->getConnection()->addIndex(
  224. $installer->getTable('wishlist/item'),
  225. $installer->getIdxName('wishlist/item', array('wishlist_id')),
  226. array('wishlist_id')
  227. );
  228. $installer->getConnection()->addIndex(
  229. $installer->getTable('wishlist/item'),
  230. $installer->getIdxName('wishlist/item', array('product_id')),
  231. array('product_id')
  232. );
  233. $installer->getConnection()->addIndex(
  234. $installer->getTable('wishlist/item'),
  235. $installer->getIdxName('wishlist/item', array('store_id')),
  236. array('store_id')
  237. );
  238. /**
  239. * Add foreign keys
  240. */
  241. $installer->getConnection()->addForeignKey(
  242. $installer->getFkName('wishlist/wishlist', 'customer_id', 'customer/entity', 'entity_id'),
  243. $installer->getTable('wishlist/wishlist'),
  244. 'customer_id',
  245. $installer->getTable('customer/entity'),
  246. 'entity_id'
  247. );
  248. $installer->getConnection()->addForeignKey(
  249. $installer->getFkName('wishlist/item', 'wishlist_id', 'wishlist/wishlist', 'wishlist_id'),
  250. $installer->getTable('wishlist/item'),
  251. 'wishlist_id',
  252. $installer->getTable('wishlist/wishlist'),
  253. 'wishlist_id'
  254. );
  255. $installer->getConnection()->addForeignKey(
  256. $installer->getFkName('wishlist/item', 'product_id', 'catalog/product', 'entity_id'),
  257. $installer->getTable('wishlist/item'),
  258. 'product_id',
  259. $installer->getTable('catalog/product'),
  260. 'entity_id'
  261. );
  262. $installer->getConnection()->addForeignKey(
  263. $installer->getFkName('wishlist/item', 'store_id', 'core/store', 'store_id'),
  264. $installer->getTable('wishlist/item'),
  265. 'store_id',
  266. $installer->getTable('core/store'),
  267. 'store_id',
  268. Varien_Db_Ddl_Table::ACTION_SET_NULL
  269. );
  270. $installer->getConnection()->addForeignKey(
  271. $installer->getFkName('wishlist/item_option', 'wishlist_item_id', 'wishlist/item', 'wishlist_item_id'),
  272. $installer->getTable('wishlist/item_option'),
  273. 'wishlist_item_id',
  274. $installer->getTable('wishlist/item'),
  275. 'wishlist_item_id'
  276. );
  277. $installer->endSetup();