Guest User

Untitled

a guest
Jan 6th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.27 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. namespace EureciaCatalogSetup;
  5.  
  6. use MagentoFrameworkSetupInstallSchemaInterface;
  7. use MagentoFrameworkSetupModuleContextInterface;
  8. use MagentoFrameworkSetupSchemaSetupInterface;
  9. use MagentoFrameworkDBDdlTable;
  10. use MagentoFrameworkDBAdapterAdapterInterface;
  11.  
  12. class InstallSchema implements InstallSchemaInterface
  13. {
  14.  
  15. /**
  16. * {@inheritdoc}
  17. */
  18. public function install(
  19. SchemaSetupInterface $setup,
  20. ModuleContextInterface $context
  21. ) {
  22. $installer = $setup;
  23. $installer->startSetup();
  24.  
  25. // Get eurecia_catalog table
  26. $tableName = $installer->getTable('eurecia_providers');
  27. // Check if the table already exists
  28. if ($installer->getConnection()->isTableExists($tableName) != true) {
  29. // Create eurecia_catalog table
  30. $table = $installer->getConnection()
  31. ->newTable($tableName)
  32. ->addColumn(
  33. 'id_provider',
  34. Table::TYPE_INTEGER,
  35. null,
  36. [
  37. 'identity' => true,
  38. 'unsigned' => true,
  39. 'nullable' => false,
  40. 'primary' => true
  41. ],
  42. 'ID Provider'
  43. )
  44. ->addColumn(
  45. 'name',
  46. Table::TYPE_TEXT,
  47. null,
  48. ['nullable' => false, 'default' => ''],
  49. 'Name'
  50. )
  51. ->addColumn(
  52. 'subdomain',
  53. Table::TYPE_TEXT,
  54. null,
  55. ['nullable' => false, 'default' => ''],
  56. 'Subdomain'
  57. )
  58. ->addColumn(
  59. 'summary',
  60. Table::TYPE_TEXT,
  61. null,
  62. ['nullable' => false, 'default' => ''],
  63. 'Summary'
  64. )
  65. ->addColumn(
  66. 'address',
  67. Table::TYPE_TEXT,
  68. null,
  69. ['nullable' => false, 'default' => ''],
  70. 'Address'
  71. )
  72. ->addColumn(
  73. 'maxdist',
  74. Table::TYPE_TEXT,
  75. null,
  76. ['nullable' => false, 'default' => ''],
  77. 'Maxdist'
  78. )
  79. ->addColumn(
  80. 'status',
  81. Table::TYPE_SMALLINT,
  82. null,
  83. ['nullable' => false, 'default' => '0'],
  84. 'Status'
  85. )
  86. ->setComment('Catalog Table')
  87. ->setOption('type', 'InnoDB')
  88. ->setOption('charset', 'utf8');
  89. $installer->getConnection()->createTable($table);
  90. }
  91.  
  92. // Get eurecia_company table
  93. $tableName = $installer->getTable('eurecia_company');
  94. // Check if the table already exists
  95. if ($installer->getConnection()->isTableExists($tableName) != true) {
  96. // Create eurecia_company table
  97. $table = $installer->getConnection()
  98. ->newTable($tableName)
  99. ->addColumn(
  100. 'id_company',
  101. Table::TYPE_INTEGER,
  102. null,
  103. [
  104. 'identity' => true,
  105. 'unsigned' => true,
  106. 'nullable' => false,
  107. 'primary' => true
  108. ],
  109. 'ID Company'
  110. )
  111. ->addColumn(
  112. 'name',
  113. Table::TYPE_TEXT,
  114. null,
  115. ['nullable' => false, 'default' => ''],
  116. 'Name'
  117. )
  118. ->addColumn(
  119. 'subdomain',
  120. Table::TYPE_TEXT,
  121. null,
  122. ['nullable' => false, 'default' => ''],
  123. 'Subdomain'
  124. )
  125. ->addColumn(
  126. 'address',
  127. Table::TYPE_TEXT,
  128. null,
  129. ['nullable' => false, 'default' => ''],
  130. 'Address'
  131. )
  132. ->addColumn(
  133. 'status',
  134. Table::TYPE_SMALLINT,
  135. null,
  136. ['nullable' => false, 'default' => '0'],
  137. 'Status'
  138. )
  139. ->setComment('Catalog Table')
  140. ->setOption('type', 'InnoDB')
  141. ->setOption('charset', 'utf8');
  142. $installer->getConnection()->createTable($table);
  143. }
  144.  
  145. if (!$installer->tableExists('eurecia_catalog_assoc')) {
  146. $table = $installer->getConnection()
  147. ->newTable($installer->getTable('eurecia_catalog_assoc'));
  148. $table->addColumn(
  149. 'id_company',
  150. Table::TYPE_INTEGER,
  151. null,
  152. [
  153. 'unsigned' => true,
  154. 'nullable' => false,
  155. 'primary' => true,
  156. ],
  157. 'company ID'
  158. )
  159. ->addColumn(
  160. 'id_provider',
  161. Table::TYPE_INTEGER,
  162. null,
  163. [
  164. 'unsigned' => true,
  165. 'nullable' => false,
  166. 'primary' => true,
  167. ],
  168. 'provider ID'
  169. )
  170. ->addColumn(
  171. 'position',
  172. Table::TYPE_INTEGER,
  173. null,
  174. [
  175. 'nullable' => false,
  176. 'default' => '0'
  177. ],
  178. 'Position'
  179. )
  180. ->addIndex(
  181. $installer->getIdxName('eurecia_catalog_assoc', ['id_company']),
  182. ['id_company']
  183. )
  184. ->addIndex(
  185. $installer->getIdxName('eurecia_catalog_assoc', ['id_provider']),
  186. ['id_provider']
  187. )
  188. ->addForeignKey(
  189. $installer->getFkName(
  190. 'eurecia_catalog_assoc',
  191. 'id_company',
  192. 'eurecia_company',
  193. 'id_company'
  194. ),
  195. 'id_company',
  196. $installer->getTable('eurecia_company'),
  197. 'id_company',
  198. Table::ACTION_CASCADE,
  199. Table::ACTION_CASCADE
  200. )
  201. ->addForeignKey(
  202. $installer->getFkName(
  203. 'eurecia_catalog_assoc',
  204. 'id_provider',
  205. 'eurecia_providers',
  206. 'id_provider'
  207. ),
  208. 'id_provider',
  209. $installer->getTable('eurecia_providers'),
  210. 'id_provider',
  211. Table::ACTION_CASCADE,
  212. Table::ACTION_CASCADE
  213. )
  214. ->addIndex(
  215. $installer->getIdxName(
  216. 'eurecia_catalog_assoc',
  217. [
  218. 'id_company',
  219. 'id_provider'
  220. ],
  221. AdapterInterface::INDEX_TYPE_UNIQUE
  222. ),
  223. [
  224. 'id_company',
  225. 'id_provider'
  226. ],
  227. [
  228. 'type' => AdapterInterface::INDEX_TYPE_UNIQUE
  229. ]
  230. )
  231. ->setComment('Company to provider Link Table');
  232. $installer->getConnection()->createTable($table);
  233. }
  234.  
  235. $setup->endSetup();
  236. }
  237. }
  238.  
  239. ->addColumn(
  240. 'id_company',
  241. Table::TYPE_INTEGER,
  242. 10,
  243. [
  244. 'identity' => true,
  245. 'unsigned' => true,
  246. 'nullable' => false,
  247. 'primary' => true
  248. ],
  249. 'ID Company'
  250. )
Add Comment
Please, Sign In to add comment