/app/code/core/Mage/Widget/sql/widget_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php

https://gitlab.com/LisovyiEvhenii/ismextensions · PHP · 351 lines · 281 code · 30 blank · 40 comment · 0 complexity · e6c5010f5267ac8b0c8088ba1bce060e 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_Widget
  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('widget/widget_instance_page'),
  34. 'FK_WIDGET_WIDGET_INSTANCE_ID'
  35. );
  36. $installer->getConnection()->dropForeignKey(
  37. $installer->getTable('widget/widget_instance_page_layout'),
  38. 'FK_WIDGET_WIDGET_INSTANCE_LAYOUT_UPDATE_ID'
  39. );
  40. $installer->getConnection()->dropForeignKey(
  41. $installer->getTable('widget/widget_instance_page_layout'),
  42. 'FK_WIDGET_WIDGET_INSTANCE_PAGE_ID'
  43. );
  44. /**
  45. * Drop indexes
  46. */
  47. $installer->getConnection()->dropIndex(
  48. $installer->getTable('widget/widget'),
  49. 'IDX_CODE'
  50. );
  51. $installer->getConnection()->dropIndex(
  52. $installer->getTable('widget/widget_instance_page'),
  53. 'IDX_WIDGET_WIDGET_INSTANCE_ID'
  54. );
  55. $installer->getConnection()->dropIndex(
  56. $installer->getTable('widget/widget_instance_page_layout'),
  57. 'PAGE_ID'
  58. );
  59. $installer->getConnection()->dropIndex(
  60. $installer->getTable('widget/widget_instance_page_layout'),
  61. 'IDX_WIDGET_WIDGET_INSTANCE_PAGE_ID'
  62. );
  63. $installer->getConnection()->dropIndex(
  64. $installer->getTable('widget/widget_instance_page_layout'),
  65. 'IDX_WIDGET_WIDGET_INSTANCE_LAYOUT_UPDATE_ID'
  66. );
  67. /**
  68. * Change columns
  69. */
  70. $tables = array(
  71. $installer->getTable('widget/widget') => array(
  72. 'columns' => array(
  73. 'widget_id' => array(
  74. 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
  75. 'identity' => true,
  76. 'unsigned' => true,
  77. 'nullable' => false,
  78. 'primary' => true,
  79. 'comment' => 'Widget Id'
  80. ),
  81. 'parameters' => array(
  82. 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
  83. 'length' => '64K',
  84. 'comment' => 'Parameters'
  85. )
  86. ),
  87. 'comment' => 'Preconfigured Widgets'
  88. ),
  89. $installer->getTable('widget/widget_instance') => array(
  90. 'columns' => array(
  91. 'instance_id' => array(
  92. 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
  93. 'identity' => true,
  94. 'unsigned' => true,
  95. 'nullable' => false,
  96. 'primary' => true,
  97. 'comment' => 'Instance Id'
  98. ),
  99. 'package_theme' => array(
  100. 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
  101. 'length' => 255,
  102. 'comment' => 'Package Theme'
  103. ),
  104. 'title' => array(
  105. 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
  106. 'length' => 255,
  107. 'comment' => 'Widget Title'
  108. ),
  109. 'store_ids' => array(
  110. 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
  111. 'length' => 255,
  112. 'nullable' => false,
  113. 'default' => '0',
  114. 'comment' => 'Store ids'
  115. ),
  116. 'widget_parameters' => array(
  117. 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
  118. 'length' => '64K',
  119. 'comment' => 'Widget parameters'
  120. ),
  121. 'sort_order' => array(
  122. 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
  123. 'unsigned' => true,
  124. 'nullable' => false,
  125. 'default' => '0',
  126. 'comment' => 'Sort order'
  127. )
  128. ),
  129. 'comment' => 'Instances of Widget for Package Theme'
  130. ),
  131. $installer->getTable('widget/widget_instance_page') => array(
  132. 'columns' => array(
  133. 'page_id' => array(
  134. 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
  135. 'identity' => true,
  136. 'unsigned' => true,
  137. 'nullable' => false,
  138. 'primary' => true,
  139. 'comment' => 'Page Id'
  140. ),
  141. 'instance_id' => array(
  142. 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
  143. 'unsigned' => true,
  144. 'nullable' => false,
  145. 'default' => '0',
  146. 'comment' => 'Instance Id'
  147. ),
  148. 'layout_handle' => array(
  149. 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
  150. 'length' => 255,
  151. 'comment' => 'Layout Handle'
  152. ),
  153. 'block_reference' => array(
  154. 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
  155. 'length' => 255,
  156. 'comment' => 'Block Reference'
  157. ),
  158. 'entities' => array(
  159. 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
  160. 'length' => '64K',
  161. 'comment' => 'Catalog entities (comma separated)'
  162. )
  163. ),
  164. 'comment' => 'Instance of Widget on Page'
  165. ),
  166. $installer->getTable('widget/widget_instance_page_layout') => array(
  167. 'columns' => array(
  168. 'page_id' => array(
  169. 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
  170. 'unsigned' => true,
  171. 'nullable' => false,
  172. 'primary' => true,
  173. 'default' => '0',
  174. 'comment' => 'Page Id'
  175. ),
  176. 'layout_update_id' => array(
  177. 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
  178. 'unsigned' => true,
  179. 'nullable' => false,
  180. 'primary' => true,
  181. 'default' => '0',
  182. 'comment' => 'Layout Update Id'
  183. )
  184. ),
  185. 'comment' => 'Layout updates'
  186. )
  187. );
  188. $installer->getConnection()->modifyTables($tables);
  189. $installer->getConnection()->changeColumn(
  190. $installer->getTable('widget/widget'),
  191. 'code',
  192. 'widget_code',
  193. array(
  194. 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
  195. 'length' => 255,
  196. 'comment' => 'Widget code for template directive'
  197. )
  198. );
  199. $installer->getConnection()->changeColumn(
  200. $installer->getTable('widget/widget'),
  201. 'type',
  202. 'widget_type',
  203. array(
  204. 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
  205. 'length' => 255,
  206. 'comment' => 'Widget Type'
  207. )
  208. );
  209. $installer->getConnection()->changeColumn(
  210. $installer->getTable('widget/widget_instance'),
  211. 'type',
  212. 'instance_type',
  213. array(
  214. 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
  215. 'length' => 255,
  216. 'comment' => 'Instance Type'
  217. )
  218. );
  219. $installer->getConnection()->changeColumn(
  220. $installer->getTable('widget/widget_instance_page'),
  221. 'group',
  222. 'page_group',
  223. array(
  224. 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
  225. 'length' => 25,
  226. 'comment' => 'Block Group Type'
  227. )
  228. );
  229. $installer->getConnection()->changeColumn(
  230. $installer->getTable('widget/widget_instance_page'),
  231. 'for',
  232. 'page_for',
  233. array(
  234. 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
  235. 'length' => 25,
  236. 'comment' => 'For instance entities'
  237. )
  238. );
  239. $installer->getConnection()->changeColumn(
  240. $installer->getTable('widget/widget_instance_page'),
  241. 'template',
  242. 'page_template',
  243. array(
  244. 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
  245. 'length' => 255,
  246. 'comment' => 'Path to widget template'
  247. )
  248. );
  249. /**
  250. * Add indexes
  251. */
  252. $installer->getConnection()->addIndex(
  253. $installer->getTable('widget/widget'),
  254. $installer->getIdxName('widget/widget', array('widget_code')),
  255. array('widget_code')
  256. );
  257. $installer->getConnection()->addIndex(
  258. $installer->getTable('widget/widget_instance_page'),
  259. $installer->getIdxName('widget/widget_instance_page', array('instance_id')),
  260. array('instance_id')
  261. );
  262. $installer->getConnection()->addIndex(
  263. $installer->getTable('widget/widget_instance_page_layout'),
  264. $installer->getIdxName(
  265. 'widget/widget_instance_page_layout',
  266. array('layout_update_id', 'page_id'),
  267. Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE
  268. ),
  269. array('layout_update_id', 'page_id'),
  270. Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE
  271. );
  272. $installer->getConnection()->addIndex(
  273. $installer->getTable('widget/widget_instance_page_layout'),
  274. $installer->getIdxName('widget/widget_instance_page_layout', array('page_id')),
  275. array('page_id')
  276. );
  277. $installer->getConnection()->addIndex(
  278. $installer->getTable('widget/widget_instance_page_layout'),
  279. $installer->getIdxName('widget/widget_instance_page_layout', array('layout_update_id')),
  280. array('layout_update_id')
  281. );
  282. /**
  283. * Add foreign keys
  284. */
  285. $installer->getConnection()->addForeignKey(
  286. $installer->getFkName(
  287. 'widget/widget_instance_page',
  288. 'instance_id',
  289. 'widget/widget_instance',
  290. 'instance_id'
  291. ),
  292. $installer->getTable('widget/widget_instance_page'),
  293. 'instance_id',
  294. $installer->getTable('widget/widget_instance'),
  295. 'instance_id'
  296. );
  297. $installer->getConnection()->addForeignKey(
  298. $installer->getFkName(
  299. 'widget/widget_instance_page_layout',
  300. 'page_id',
  301. 'widget/widget_instance_page',
  302. 'page_id'
  303. ),
  304. $installer->getTable('widget/widget_instance_page_layout'),
  305. 'page_id',
  306. $installer->getTable('widget/widget_instance_page'),
  307. 'page_id'
  308. );
  309. $installer->getConnection()->addForeignKey(
  310. $installer->getFkName(
  311. 'widget/widget_instance_page_layout',
  312. 'layout_update_id',
  313. 'core/layout_update',
  314. 'layout_update_id'
  315. ),
  316. $installer->getTable('widget/widget_instance_page_layout'),
  317. 'layout_update_id',
  318. $installer->getTable('core/layout_update'),
  319. 'layout_update_id'
  320. );
  321. $installer->endSetup();