Пример #1
0
 public function fire()
 {
     $clearAll = true;
     if ($this->input->getOption('config-only')) {
         $clearAll = false;
         Config::clearCache();
         $this->info('Config cache cleared.');
     }
     if ($this->input->getOption('meta-only')) {
         $clearAll = false;
         Db::clearMetadata();
         $this->info('Model metadata cleared.');
     }
     if ($this->input->getOption('locale-only')) {
         $clearAll = false;
         I18n::clearCache();
         $this->info('Locale cache cleared.');
     }
     if ($this->input->getOption('assets-only')) {
         $clearAll = false;
         View::clearAssetsCache();
         $this->info('Assets cache cleared.');
     }
     if ($clearAll) {
         Cache::flush();
         Config::clearCache();
         $this->info('Cache cleared.');
     }
     Events::fire('cache:after_clear', $this);
 }
Пример #2
0
 public function initialize()
 {
     parent::initialize();
     $db = Db::connection();
     $db->tableExists($this->_table) or $this->createTable();
     $db->delete($this->_table);
 }
Пример #3
0
 public function setUp()
 {
     parent::setUp();
     Config::set('counter.default', 'rds');
     Counter::register($this->di);
     $db = Db::connection();
     $db->tableExists('counter') and $db->dropTable('counter');
 }
Пример #4
0
 public function setUp()
 {
     parent::setUp();
     Db::clearMetadata();
     $this->di->set(Order::class, TestOrderModel::class);
     $this->di->set(OrderData::class, TestOrderDataModel::class);
     $this->getOrderModelInstance()->delete();
 }
Пример #5
0
 public function setUp()
 {
     parent::setUp();
     Db::clearMetadata();
     $this->di->set(User::class, TestUserModel::class);
     $this->di->set(UserProfile::class, TestUserProfileModel::class);
     $this->getUserModelInstance()->delete();
 }
Пример #6
0
 protected static function createConfigTable()
 {
     $db = Db::connection();
     $db->createTable('config', null, ['columns' => [new Column('key', ['type' => Column::TYPE_VARCHAR, 'size' => 32, 'notNull' => true, 'primary' => true]), new Column('value', ['type' => Column::TYPE_TEXT])]]);
     if (PhwoolconConfig::runningUnitTest()) {
         static::saveConfig('_testing', ['k' => 'v']);
     }
 }
Пример #7
0
 protected function revertMigration($filename)
 {
     $db = $this->db;
     $db->begin();
     $file = migrationPath($filename);
     try {
         $this->logAndShowInfo(sprintf('Start reverting migration "%s"', $filename));
         $migration = (include $file);
         if (isset($migration['down']) && is_callable($migration['down'])) {
             call_user_func($migration['down'], $db, $this);
         }
         $this->migrationExecuted($filename, false);
         $db->commit();
         Db::clearMetadata();
         $this->logAndShowInfo(sprintf('Finish reverting migration "%s"', $filename));
     } catch (Exception $e) {
         $db->rollback();
         Log::exception($e);
         $this->error(sprintf('Error when reverting migration "%s"', $filename));
         $this->error($e->getMessage());
     }
     // @codeCoverageIgnoreEnd
 }
Пример #8
0
 public function setUp()
 {
     $_SERVER['SCRIPT_NAME'] = '/index.php';
     $_SERVER['PHWOOLCON_PHALCON_VERSION'] = Version::getId();
     /* @var Di $di */
     $di = $this->di = Di::getDefault();
     Events::register($di);
     DiFix::register($di);
     Db::register($di);
     Cache::register($di);
     Log::register($di);
     Config::register($di);
     Counter::register($this->di);
     Aliases::register($di);
     I18n::register($di);
     Cookies::register($di);
     Session::register($di);
     Cache::flush();
     Config::clearCache();
     parent::setUp();
     $class = get_class($this);
     Log::debug("================== Running {$class}::{$this->getName()}() ... ==================");
     Timer::start();
 }
Пример #9
0
 /**
  * @codeCoverageIgnore
  */
 protected function createTable()
 {
     $this->db->createTable($this->table, null, ['columns' => [new Column('id', ['type' => Column::TYPE_BIGINTEGER, 'size' => 20, 'unsigned' => true, 'notNull' => true, 'primary' => true, 'autoIncrement' => true]), new Column('connection', ['type' => Column::TYPE_TEXT, 'notNull' => false]), new Column('queue', ['type' => Column::TYPE_TEXT, 'notNull' => false]), new Column('payload', ['type' => 'LONGTEXT', 'notNull' => false]), new Column('failed_at', ['type' => Column::TYPE_TIMESTAMP, 'notNull' => true, 'default' => 'CURRENT_TIMESTAMP'])], 'options' => ['TABLE_COLLATION' => Db::getDefaultTableCharset()]]);
 }
Пример #10
0
 public function reset($keyName)
 {
     $db = Db::connection();
     $db->updateAsDict($this->table, ['value' => 0], ['conditions' => $this->updateCondition, 'bind' => [$keyName]]);
 }
Пример #11
0
 public function startIsolated()
 {
     $this->setWorkerStarted(false);
     $serverProcess = new SwooleProcess(function () {
         $this->start();
     }, true);
     $serverProcess->start();
     Db::reconnect();
     $retry = 20;
     while ($retry && !$this->isWorkerStarted()) {
         usleep(100000.0);
         --$retry;
     }
     $this->isWorkerStarted() or Log::error('Failed to start');
     return $serverProcess;
 }
Пример #12
0
use Phalcon\Version;
use Phwoolcon\Aliases;
use Phwoolcon\Cache;
use Phwoolcon\Config;
use Phwoolcon\Cookies;
use Phwoolcon\Db;
use Phwoolcon\DiFix;
use Phwoolcon\Events;
use Phwoolcon\I18n;
use Phwoolcon\Log;
use Phwoolcon\Queue;
use Phwoolcon\Router;
use Phwoolcon\Session;
use Phwoolcon\Util\Counter;
use Phwoolcon\View;
$_SERVER['PHWOOLCON_PHALCON_VERSION'] = Version::getId();
Events::register($di);
DiFix::register($di);
Db::register($di);
Cache::register($di);
Log::register($di);
Config::register($di);
Counter::register($di);
Aliases::register($di);
Router::register($di);
I18n::register($di);
Cookies::register($di);
Session::register($di);
View::register($di);
Queue::register($di);
$loader->registerNamespaces(Config::get('app.autoload.namespaces', []), true);
Пример #13
0
 protected function runMigration()
 {
     $db = $this->db;
     $migrated = false;
     foreach (glob(migrationPath('*.php')) as $file) {
         $filename = basename($file);
         if ($this->migrationExecuted($filename)) {
             continue;
         }
         $migrated = true;
         $this->logAndShowInfo(sprintf('Start migration "%s"', $filename));
         $db->begin();
         try {
             $migration = (include $file);
             if (isset($migration['up']) && is_callable($migration['up'])) {
                 call_user_func($migration['up'], $db, $this);
             }
             $this->migrationExecuted($filename, true);
             $db->commit();
         } catch (Exception $e) {
             $db->rollback();
             Log::exception($e);
             $this->error(sprintf('Error in migration "%s"', $filename));
             $this->error($e->getMessage());
             return;
         }
         // @codeCoverageIgnoreEnd
         $this->logAndShowInfo(sprintf('Finish migration "%s"', $filename));
     }
     if ($migrated) {
         Db::clearMetadata();
     } else {
         $this->info('Nothing to be migrated.');
     }
     // @codeCoverageIgnoreEnd
 }
Пример #14
0
 public function testReconnect()
 {
     $this->assertEquals('value', Db::reconnect()->query('SELECT "value" v')->fetch()['v'], 'DB reconnect failed');
 }
Пример #15
0
 public function onWorkerStart(SwooleServer $server, $workerId)
 {
     Db::reconnect();
     @cli_set_process_title($this->name . ': worker process ' . $workerId);
 }