From a0562a3dd4151eded1394fd660b7cd65d6a6c6f5 Mon Sep 17 00:00:00 2001 From: SilverFire - Dmitry Naumenko Date: Mon, 24 Apr 2017 17:45:26 +0300 Subject: [PATCH] Added package avoiding --- src/console/MaintenanceController.php | 2 +- src/repositories/PackageRepository.php | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/console/MaintenanceController.php b/src/console/MaintenanceController.php index 67f33d2..ca69da7 100644 --- a/src/console/MaintenanceController.php +++ b/src/console/MaintenanceController.php @@ -67,7 +67,7 @@ public function actionSyncToDb() */ public function actionUpdateExpired() { - $packages = $this->packageRepository->getExpired(); + $packages = $this->packageRepository->getExpiredForUpdate(); foreach ($packages as $package) { $package->load(); diff --git a/src/repositories/PackageRepository.php b/src/repositories/PackageRepository.php index facc172..608112b 100644 --- a/src/repositories/PackageRepository.php +++ b/src/repositories/PackageRepository.php @@ -55,10 +55,22 @@ public function update(AssetPackage $package) { return $this->db->createCommand()->update('package', [ 'last_update' => $package->getUpdateTime() - ], [ + ], $this->getWhereCondition($package))->execute(); + } + + public function markAvoided(AssetPackage $package) + { + $this->db->createCommand()->update('package', [ + 'is_avoided' => true + ], $this->getWhereCondition($package))->execute(); + } + + protected function getWhereCondition(AssetPackage $package) + { + return [ 'type' => $package->getType(), 'name' => $package->getName(), - ])->execute(); + ]; } /** @@ -76,12 +88,13 @@ public function exists(AssetPackage $package) /** * @return \hiqdev\assetpackagist\models\AssetPackage[] */ - public function getExpired() + public function getExpiredForUpdate() { $rows = (new Query()) ->from('package') ->where(['<', 'last_update', time() - 60 * 60 * 24 * 7]) // Older than 7 days ->andWhere(['not', ['last_update' => null]]) + ->andWhere(['is_avoided' => null]) ->all(); return $this->hydrate($rows);