123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- namespace yii\test;
- use Yii;
- class InitDbFixture extends DbFixture
- {
-
- public $initScript = '@app/tests/fixtures/initdb.php';
-
- public $schemas = [''];
-
- public function beforeLoad()
- {
- $this->checkIntegrity(false);
- }
-
- public function afterLoad()
- {
- $this->checkIntegrity(true);
- }
-
- public function load()
- {
- $file = Yii::getAlias($this->initScript);
- if (is_file($file)) {
- require $file;
- }
- }
-
- public function beforeUnload()
- {
- $this->checkIntegrity(false);
- }
-
- public function afterUnload()
- {
- $this->checkIntegrity(true);
- }
-
- public function checkIntegrity($check)
- {
- if (!$this->db instanceof \yii\db\Connection) {
- return;
- }
- foreach ($this->schemas as $schema) {
- $this->db->createCommand()->checkIntegrity($check, $schema)->execute();
- }
- }
- }
|