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

/magento/app/code/core/Mage/Api/sql/api_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php

https://bitbucket.org/jit_bec/shopifine
PHP | 375 lines | 310 code | 25 blank | 40 comment | 0 complexity | 3303d916e3158a32714718c269b359e2 MD5 | raw file
Possible License(s): LGPL-3.0
  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_Api
  23. * @copyright Copyright (c) 2012 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('api/rule'),
  34. 'FK_API_RULE'
  35. );
  36. $installer->getConnection()->dropForeignKey(
  37. $installer->getTable('api/session'),
  38. 'FK_API_SESSION_USER'
  39. );
  40. /**
  41. * Drop indexes
  42. */
  43. $installer->getConnection()->dropIndex(
  44. $installer->getTable('api/role'),
  45. 'PARENT_ID'
  46. );
  47. $installer->getConnection()->dropIndex(
  48. $installer->getTable('api/role'),
  49. 'TREE_LEVEL'
  50. );
  51. $installer->getConnection()->dropIndex(
  52. $installer->getTable('api/rule'),
  53. 'RESOURCE'
  54. );
  55. $installer->getConnection()->dropIndex(
  56. $installer->getTable('api/rule'),
  57. 'ROLE_ID'
  58. );
  59. $installer->getConnection()->dropIndex(
  60. $installer->getTable('api/session'),
  61. 'API_SESSION_USER'
  62. );
  63. $installer->getConnection()->dropIndex(
  64. $installer->getTable('api/session'),
  65. 'API_SESSION_SESSID'
  66. );
  67. /*
  68. * Change columns
  69. */
  70. $tables = array(
  71. $installer->getTable('api/assert') => array(
  72. 'columns' => array(
  73. 'assert_id' => array(
  74. 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
  75. 'identity' => true,
  76. 'unsigned' => true,
  77. 'nullable' => false,
  78. 'primary' => true,
  79. 'comment' => 'Assert id'
  80. ),
  81. 'assert_type' => array(
  82. 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
  83. 'length' => 20,
  84. 'comment' => 'Assert type'
  85. ),
  86. 'assert_data' => array(
  87. 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
  88. 'length' => '64K',
  89. 'comment' => 'Assert additional data'
  90. )
  91. ),
  92. 'comment' => 'Api ACL Asserts'
  93. ),
  94. $installer->getTable('api/role') => array(
  95. 'columns' => array(
  96. 'role_id' => array(
  97. 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
  98. 'identity' => true,
  99. 'unsigned' => true,
  100. 'nullable' => false,
  101. 'primary' => true,
  102. 'comment' => 'Role id'
  103. ),
  104. 'parent_id' => array(
  105. 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
  106. 'unsigned' => true,
  107. 'nullable' => false,
  108. 'default' => '0',
  109. 'comment' => 'Parent role id'
  110. ),
  111. 'tree_level' => array(
  112. 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
  113. 'unsigned' => true,
  114. 'nullable' => false,
  115. 'default' => '0',
  116. 'comment' => 'Role level in tree'
  117. ),
  118. 'sort_order' => array(
  119. 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
  120. 'unsigned' => true,
  121. 'nullable' => false,
  122. 'default' => '0',
  123. 'comment' => 'Sort order to display on admin area'
  124. ),
  125. 'role_type' => array(
  126. 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
  127. 'length' => 1,
  128. 'nullable' => false,
  129. 'default' => '0',
  130. 'comment' => 'Role type'
  131. ),
  132. 'user_id' => array(
  133. 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
  134. 'unsigned' => true,
  135. 'nullable' => false,
  136. 'default' => '0',
  137. 'comment' => 'User id'
  138. ),
  139. 'role_name' => array(
  140. 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
  141. 'length' => 50,
  142. 'comment' => 'Role name'
  143. )
  144. ),
  145. 'comment' => 'Api ACL Roles'
  146. ),
  147. $installer->getTable('api/rule') => array(
  148. 'columns' => array(
  149. 'rule_id' => array(
  150. 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
  151. 'identity' => true,
  152. 'unsigned' => true,
  153. 'nullable' => false,
  154. 'primary' => true,
  155. 'comment' => 'Api rule Id'
  156. ),
  157. 'role_id' => array(
  158. 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
  159. 'unsigned' => true,
  160. 'nullable' => false,
  161. 'default' => '0',
  162. 'comment' => 'Api role Id'
  163. ),
  164. 'resource_id' => array(
  165. 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
  166. 'length' => 255,
  167. 'comment' => 'Module code'
  168. ),
  169. 'assert_id' => array(
  170. 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
  171. 'unsigned' => true,
  172. 'nullable' => false,
  173. 'default' => '0',
  174. 'comment' => 'Assert id'
  175. ),
  176. 'role_type' => array(
  177. 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
  178. 'length' => 1,
  179. 'comment' => 'Role type'
  180. )
  181. ),
  182. 'comment' => 'Api ACL Rules'
  183. ),
  184. $installer->getTable('api/user') => array(
  185. 'columns' => array(
  186. 'user_id' => array(
  187. 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
  188. 'identity' => true,
  189. 'unsigned' => true,
  190. 'nullable' => false,
  191. 'primary' => true,
  192. 'comment' => 'User id'
  193. ),
  194. 'firstname' => array(
  195. 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
  196. 'length' => 32,
  197. 'comment' => 'First name'
  198. ),
  199. 'lastname' => array(
  200. 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
  201. 'length' => 32,
  202. 'comment' => 'Last name'
  203. ),
  204. 'email' => array(
  205. 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
  206. 'length' => 128,
  207. 'comment' => 'Email'
  208. ),
  209. 'username' => array(
  210. 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
  211. 'length' => 40,
  212. 'comment' => 'Nickname'
  213. ),
  214. 'api_key' => array(
  215. 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
  216. 'length' => 40,
  217. 'comment' => 'Api key'
  218. ),
  219. 'created' => array(
  220. 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP,
  221. 'nullable' => false,
  222. 'comment' => 'User record create date'
  223. ),
  224. 'modified' => array(
  225. 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP,
  226. 'comment' => 'User record modify date'
  227. ),
  228. 'lognum' => array(
  229. 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
  230. 'unsigned' => true,
  231. 'nullable' => false,
  232. 'default' => '0',
  233. 'comment' => 'Quantity of log ins'
  234. ),
  235. 'reload_acl_flag' => array(
  236. 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
  237. 'nullable' => false,
  238. 'default' => '0',
  239. 'comment' => 'Refresh ACL flag'
  240. ),
  241. 'is_active' => array(
  242. 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
  243. 'nullable' => false,
  244. 'default' => '1',
  245. 'comment' => 'Account status'
  246. )
  247. ),
  248. 'comment' => 'Api Users'
  249. ),
  250. $installer->getTable('api/session') => array(
  251. 'columns' => array(
  252. 'user_id' => array(
  253. 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
  254. 'unsigned' => true,
  255. 'nullable' => false,
  256. 'default' => '0',
  257. 'comment' => 'User id'
  258. ),
  259. 'logdate' => array(
  260. 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP,
  261. 'nullable' => false,
  262. 'comment' => 'Login date'
  263. ),
  264. 'sessid' => array(
  265. 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
  266. 'length' => 40,
  267. 'comment' => 'Sessioin id'
  268. )
  269. ),
  270. 'comment' => 'Api Sessions'
  271. )
  272. );
  273. $installer->getConnection()->modifyTables($tables);
  274. $installer->getConnection()->changeColumn(
  275. $installer->getTable('api/rule'),
  276. 'privileges',
  277. 'api_privileges',
  278. array(
  279. 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
  280. 'length' => 20,
  281. 'comment' => 'Privileges'
  282. )
  283. );
  284. $installer->getConnection()->changeColumn(
  285. $installer->getTable('api/rule'),
  286. 'permission',
  287. 'api_permission',
  288. array(
  289. 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
  290. 'length' => 10,
  291. 'comment' => 'Permission'
  292. )
  293. );
  294. /**
  295. * Add indexes
  296. */
  297. $installer->getConnection()->addIndex(
  298. $installer->getTable('api/rule'),
  299. $installer->getIdxName('api/rule', array('resource_id', 'role_id')),
  300. array('resource_id', 'role_id'),
  301. Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX
  302. );
  303. $installer->getConnection()->addIndex(
  304. $installer->getTable('api/rule'),
  305. $installer->getIdxName('api/rule', array('role_id', 'resource_id')),
  306. array('role_id', 'resource_id'),
  307. Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX
  308. );
  309. $installer->getConnection()->addIndex(
  310. $installer->getTable('api/session'),
  311. $installer->getIdxName('api/session', array('user_id')),
  312. array('user_id'),
  313. Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX
  314. );
  315. $installer->getConnection()->addIndex(
  316. $installer->getTable('api/session'),
  317. $installer->getIdxName('api/session', array('sessid')),
  318. array('sessid'),
  319. Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX
  320. );
  321. $installer->getConnection()->addIndex(
  322. $installer->getTable('api/role'),
  323. $installer->getIdxName('api/role', array('parent_id', 'sort_order')),
  324. array('parent_id', 'sort_order'),
  325. Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX
  326. );
  327. $installer->getConnection()->addIndex(
  328. $installer->getTable('api/role'),
  329. $installer->getIdxName('api/role', array('tree_level')),
  330. array('tree_level'),
  331. Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX
  332. );
  333. /**
  334. * Add foreign keys
  335. */
  336. $installer->getConnection()->addForeignKey(
  337. $installer->getFkName('api/rule', 'role_id', 'api/role', 'role_id'),
  338. $installer->getTable('api/rule'),
  339. 'role_id',
  340. $installer->getTable('api/role'),
  341. 'role_id'
  342. );
  343. $installer->getConnection()->addForeignKey(
  344. $installer->getFkName('api/session', 'user_id', 'api/user', 'user_id'),
  345. $installer->getTable('api/session'),
  346. 'user_id',
  347. $installer->getTable('api/user'),
  348. 'user_id'
  349. );
  350. $installer->endSetup();