Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. <?php
  2.  
  3. class m180117_170602_add_reports_to_BE_marketplace_menu extends CsDbMigration
  4. {
  5. /**
  6. * @inheritDoc
  7. */
  8. public function __construct()
  9. {
  10. Yii::app()->getModule('marketplace');
  11. }
  12.  
  13. public function safeUp()
  14. {
  15.  
  16. $parentId = $this->queryScalar("SELECT Id FROM Menu WHERE ParentId IS NULL AND Operation = 'MenuMarketplace'");
  17.  
  18. if (!$parentId) {
  19. throw new Exception('cannot find parent menu');
  20. }
  21.  
  22. $priority = $this->queryScalar('SELECT COALESCE(MAX(Priority),0)+1 FROM Menu WHERE ParentId = :parent', ['parent' => $parentId]);
  23.  
  24. $this->execute('SET FOREIGN_KEY_CHECKS = 0;');
  25. $this->insert('AuthItem', ['name' => 'MenuMarketplace_Reports', 'type' => 1]);
  26. $this->insert('Menu', [
  27. 'MenuLabel' => 'Rapoarte marketplace',
  28. 'ParentId' => $parentId,
  29. 'Operation' => 'MenuMarketplace_Reports',
  30. 'URL' => '',
  31. 'Priority' => $priority,
  32. 'ModuleId' => 'marketplace',
  33. 'CreationDate' => date('Y-m-d H:i:s'),
  34. 'CreationUserId' => Yii::app()->user->id,
  35. 'LastUpdate' => date('Y-m-d H:i:s'),
  36. 'LastUpdateUserId' => Yii::app()->user->id,
  37. ]);
  38. $parentId = $this->dbConnection->getLastInsertID();
  39. $this->insert('AuthItem', ['name' => 'MenuMarketplace_Reports_Transport', 'type' => 1]);
  40. $this->insert('Menu', [
  41. 'MenuLabel' => 'Raport Transport',
  42. 'ParentId' => $parentId,
  43. 'Operation' => 'MenuMarketplace_Reports_Transport',
  44. 'URL' => '/backend/marketplace/reports/transport',
  45. 'Priority' => 1,
  46. 'ModuleId' => 'marketplace',
  47. 'CreationDate' => date('Y-m-d H:i:s'),
  48. 'CreationUserId' => Yii::app()->user->id,
  49. 'LastUpdate' => date('Y-m-d H:i:s'),
  50. 'LastUpdateUserId' => Yii::app()->user->id,
  51. ]);
  52. $this->execute('SET FOREIGN_KEY_CHECKS = 1;');
  53. }
  54.  
  55. public function safeDown()
  56. {
  57. $this->execute('SET FOREIGN_KEY_CHECKS = 0;');
  58. $this->delete('AuthItem', ['name' => 'MenuMarketplace_Reports_Transport']);
  59. $this->delete('Menu', ['URL' => '/backend/marketplace/reports/transport']);
  60. $this->delete('AuthItem', ['name' => 'MenuMarketplace_Reports']);
  61. $this->delete('Menu', ['MenuLabel' => 'Raport Transport']);
  62. $this->execute('SET FOREIGN_KEY_CHECKS = 1;');
  63.  
  64. }
  65.  
  66. protected function queryScalar($query, $params=[])
  67. {
  68. return $this->dbConnection->createCommand($query)->queryScalar($params);
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement