Skip to content

Commit

Permalink
Added package avoiding
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverFire committed Apr 24, 2017
1 parent 59e4260 commit a0562a3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/console/MaintenanceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function actionSyncToDb()
*/
public function actionUpdateExpired()
{
$packages = $this->packageRepository->getExpired();
$packages = $this->packageRepository->getExpiredForUpdate();

foreach ($packages as $package) {
$package->load();
Expand Down
19 changes: 16 additions & 3 deletions src/repositories/PackageRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
];
}

/**
Expand All @@ -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);
Expand Down

0 comments on commit a0562a3

Please sign in to comment.