1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace hiqdev\assetpackagist\console; |
4
|
|
|
|
5
|
|
|
use hiqdev\assetpackagist\components\StorageInterface; |
6
|
|
|
use hiqdev\assetpackagist\models\AssetPackage; |
7
|
|
|
use hiqdev\assetpackagist\repositories\PackageRepository; |
8
|
|
|
use yii\console\Controller; |
9
|
|
|
use yii\helpers\Console; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Provides maintenance actions for the asset-packagist service |
13
|
|
|
* @package hiqdev\assetpackagist\console |
14
|
|
|
*/ |
15
|
|
|
class MaintenanceController extends Controller |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var StorageInterface |
19
|
|
|
*/ |
20
|
|
|
protected $packageStorage; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var PackageRepository |
24
|
|
|
*/ |
25
|
|
|
protected $packageRepository; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* MaintenanceController constructor. |
29
|
|
|
* @param StorageInterface $packageStorage |
30
|
|
|
* @param PackageRepository $packageRepository |
31
|
|
|
* @inheritdoc |
32
|
|
|
*/ |
33
|
|
|
public function __construct($id, $module, StorageInterface $packageStorage, PackageRepository $packageRepository, $config = []) |
34
|
|
|
{ |
35
|
|
|
parent::__construct($id, $module, $config); |
36
|
|
|
|
37
|
|
|
$this->packageStorage = $packageStorage; |
38
|
|
|
$this->packageRepository = $packageRepository; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Synchronizes file system packages to the database |
43
|
|
|
*/ |
44
|
|
|
public function actionSyncToDb() |
45
|
|
|
{ |
46
|
|
|
$packages = $this->packageStorage->listPackages(); |
47
|
|
|
|
48
|
|
|
foreach ($packages as $name => $data) { |
49
|
|
|
$message = "Package %N$name%n "; |
50
|
|
|
$package = AssetPackage::fromFullName($name); |
51
|
|
|
$package->load(); |
52
|
|
|
|
53
|
|
|
$message .= $this->packageRepository->exists($package) |
54
|
|
|
? 'already exists. %BUpdated.%n' |
55
|
|
|
: 'does not exist. %GCreated.%n'; |
56
|
|
|
|
57
|
|
|
$this->packageRepository->save($package); |
58
|
|
|
|
59
|
|
|
$this->stdout(Console::renderColoredString($message . "\n")); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|