/** * Synchronize application data (packages metadata and database packages rows). * * @return void */ public function syncAction() { try { /** * Add missing packages. * Read packages files and find packages that is missing in db. * * $modulesWidgets - array of widgets that is located in modules [module => [widgets...n]]. * $notFoundWidgets - array of widgets as external packages [widgets...n]. * $packages - all packages names found at metadata files. * $widgets - all widgets names found at metadata files. */ list($modulesWidgets, $notFoundWidgets, $packages, $widgets) = $this->_checkMissingPackages(); /** * Add missing widgets from modules and from packages. */ $this->_checkMissingWidgets($modulesWidgets, $notFoundWidgets); /** * Remove unused packages. */ $this->_removeUnusedPackages($packages); /** * Remove unused widgets. */ $this->_removeUnusedWidgets($widgets); /** * Generate metadata. */ $manager = new Manager(Package::find(), $this->getDI()); $manager->generateMetadata(null, true); print ConsoleUtil::success('Application successfully synchronized.') . PHP_EOL; } catch (Exception $e) { print ConsoleUtil::error($e->getMessage()) . PHP_EOL; } }
/** * 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; } }
/** * 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; }
/** * Test action. * * @return void */ public function testAction($param1 = null, $param2 = null) { print ConsoleUtil::success('Test command success - param1: ' . $param1 . ' - param2: ' . $param2 . '.') . PHP_EOL; }
/** * Cleanup cache data. * * @return void */ public function cleanupAction() { $this->getDI()->get('app')->clearCache(); print ConsoleUtil::success('Cache successfully removed.') . PHP_EOL; }
/** * 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); } }