Exemplo n.º 1
0
 /**
  * Update database schema according to models metadata.
  *
  * @param string|null $model   Model name to update. Example: \Test\Model\Class.
  * @param bool        $cleanup Cleanup database? Drop not related tables.
  *
  * @return void
  */
 public function updateAction($model = null, $cleanup = false)
 {
     $schema = new Schema($this->getDI());
     if ($model) {
         if (!class_exists($model)) {
             print ConsoleUtil::error('Model with class "' . $model . '" doesn\'t exists.') . PHP_EOL;
             return;
         }
         $count = current($schema->updateTable($model));
         if ($count) {
             print ConsoleUtil::headLine('Table update for model: ' . $model);
             print ConsoleUtil::commandLine('Executed queries:', $count, ConsoleUtil::FG_CYAN);
         } else {
             print ConsoleUtil::success('Table is up to date');
         }
         print PHP_EOL;
     } else {
         $queriesCount = $schema->updateDatabase($cleanup);
         if (!empty($queriesCount)) {
             print ConsoleUtil::headLine('Database update:');
             foreach ($queriesCount as $model => $count) {
                 print ConsoleUtil::commandLine($model . ':', $count, ConsoleUtil::FG_CYAN);
             }
         } else {
             print ConsoleUtil::success('Database is up to date');
         }
         print PHP_EOL;
     }
 }
Exemplo n.º 2
0
 /**
  * Print special info message.
  *
  * @param string $msg Info message.
  *
  * @return void
  */
 protected function _info($msg)
 {
     print ConsoleUtil::infoLine($msg, false, 0, ConsoleUtil::FG_CYAN);
 }
Exemplo n.º 3
0
 /**
  * Install assets from modules.
  *
  * @return void
  */
 public function installAction()
 {
     $assetsManager = new Manager($this->getDI(), false);
     $assetsManager->installAssets(PUBLIC_PATH . '/themes/' . Settings::getSetting('system_theme'));
     print ConsoleUtil::success('Assets successfully installed.') . PHP_EOL;
 }
Exemplo n.º 4
0
 /**
  * Test action.
  *
  * @return void
  */
 public function testAction($param1 = null, $param2 = null)
 {
     print ConsoleUtil::success('Test command success - param1: ' . $param1 . ' - param2: ' . $param2 . '.') . PHP_EOL;
 }
Exemplo n.º 5
0
 /**
  * Check help system.
  *
  * @return bool
  */
 protected function _helpIsRequired()
 {
     if ($_SERVER['argv'][1] != 'help') {
         return false;
     }
     if (empty($_SERVER['argv'][2])) {
         $this->printAvailableCommands();
         return true;
     }
     $command = $this->_getRequiredCommand($_SERVER['argv'][2]);
     if (!$command) {
         print ConsoleUtil::warningLine('Command "' . $_SERVER['argv'][2] . '" not found.');
         return true;
     }
     $command->getHelp(!empty($_SERVER['argv'][3]) ? $_SERVER['argv'][3] : null);
     return true;
 }
Exemplo n.º 6
0
 /**
  * Cleanup cache data.
  *
  * @return void
  */
 public function cleanupAction()
 {
     $this->getDI()->get('app')->clearCache();
     print ConsoleUtil::success('Cache successfully removed.') . PHP_EOL;
 }
Exemplo n.º 7
0
 /**
  * Check passed parameters (required or no value).
  *
  * @param array $withoutValue Params without value.
  *
  * @return bool
  */
 private function _checkParameters($withoutValue)
 {
     $action = $this->_parameters['action'];
     if (!empty($this->_actions[$action]['params'])) {
         foreach ($this->_actions[$action]['params'] as $actionParams) {
             // Check required param.
             if ($actionParams['defaultValueType'] == '<required>' && empty($this->_parameters[$actionParams['name']])) {
                 print ConsoleUtil::error(sprintf('Parameter "%s" is required!', $actionParams['name']));
                 $this->getHelp($action);
                 return false;
             }
             // Check required value of param.
             if ($actionParams['defaultValueType'] != 'boolean' && in_array($actionParams['name'], $withoutValue)) {
                 print ConsoleUtil::error(sprintf('Parameter "%s" must have value!', $actionParams['name']));
                 $this->getHelp($action);
                 return false;
             }
         }
     }
     return true;
 }
Exemplo n.º 8
0
 /**
  * Check category
  *
  * @return void
  */
 public function categoryAction()
 {
     $myCategoryMap = CategoryMap::find(['status = :status:', 'bind' => ['status' => CategoryMap::STATUS_PENDING]]);
     if ($myCategoryMap) {
         foreach ($myCategoryMap as $item) {
             // Get all products from this category from haravan
             $myStore = Store::findFirstById($item->sid);
             $session = $this->getDI()->get('session');
             $session->set('shop', $myStore->name);
             $session->set('oauth_token', $myStore->accessToken);
             $total = EnHelper::getInstance('haravan', 'import')->getTotalProductsByCollectionId((int) $item->hid);
             $totalPage = ceil($total / 50);
             // Using to count queued item.
             $itemInQueue = $item->totalItemQueue;
             $itemList = [];
             if ($totalPage >= 1) {
                 for ($i = 1; $i <= $totalPage; $i++) {
                     $myProducts = EnHelper::getInstance('haravan', 'import')->getProductsByCollectionId((int) $item->hid, $i);
                     if ($myProducts) {
                         foreach ($myProducts as $product) {
                             $myProductQueue = ProductQueue::findFirst(['pid = :pid:', 'bind' => ['pid' => (int) $product->id]]);
                             if ($myProductQueue == false) {
                                 $myProductQueue = new ProductQueue();
                                 $myProductQueue->pid = (int) $product->id;
                                 $myProductQueue->pdata = json_encode($product, JSON_UNESCAPED_UNICODE);
                                 $myProductQueue->status = ProductQueue::STATUS_QUEUE;
                                 $myProductQueue->retryCount = 0;
                                 $myProductQueue->priority = 1;
                                 $myProductQueue->fcid = $item->fid;
                                 $myProductQueue->sid = $item->sid;
                                 if ($myProductQueue->create()) {
                                     //Push to Beanstalk Queue
                                     $queue = $this->getDI()->get('queue');
                                     $queue->choose('haraapp.import');
                                     $addedToQueue = $queue->put([['storeId' => $item->sid, 'haravanId' => $item->hid, 'haravanProductId' => $product->id], ['priority' => $myProductQueue->priority, 'delay' => 10, 'ttr' => 3600]]);
                                     if ($addedToQueue) {
                                         echo $item->hid . ' - added to queue.' . PHP_EOL;
                                         $itemInQueue = $itemInQueue + 1;
                                         $itemList[] = $item->hid;
                                     }
                                 } else {
                                     foreach ($myProductQueue->getMessages() as $msg) {
                                         print $msg . PHP_EOL;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             //Save to category_map table total products of this category.
             $item->totalItem = (int) $total;
             $item->totalItemQueue = (int) $itemInQueue;
             $item->status = CategoryMap::STATUS_COMPLETED;
             if (count($itemList) > 0) {
                 $item->data = json_encode($itemList);
             }
             $item->update();
             // Insert current progress to product log table.
             $myProductLog = ProductLog::findFirst('status = ' . ProductLog::STATUS_CURRENT_PROCESSING . ' AND type = ' . ProductLog::TYPE_IMPORT . ' AND sid = ' . $myStore->id);
             $myProductLog->status = ProductLog::STATUS_COMPLETED;
             $myProductLog->update();
             $myProductLog = new ProductLog();
             $myProductLog->assign(['sid' => $item->sid, 'message' => 'Category Name ' . $item->fname . ' initialize Completed. Ready in Queue.', 'type' => ProductLog::TYPE_IMPORT, 'status' => ProductLog::STATUS_CURRENT_PROCESSING, 'class' => 'succcess']);
             $myProductLog->create();
         }
     } else {
         print ConsoleUtil::success('No Category Pending found.') . PHP_EOL;
         exit(0);
     }
 }