Inheritance: extends yii\base\Object
 /**
  * @param AssetPackage $package
  * @return bool
  */
 public function exists(AssetPackage $package)
 {
     return (new Query())->from('package')->where(['type' => $package->getType(), 'name' => $package->getName()])->exists($this->db);
 }
Esempio n. 2
0
 /**
  * @inheritdoc
  */
 public function readPackage(AssetPackage $package)
 {
     $name = $package->getNormalName();
     $path = $this->buildHashedPath($name);
     if (!file_exists($path)) {
         return null;
     }
     $json = file_get_contents($path);
     $updateTime = filemtime($path);
     $hash = hash('sha256', $json);
     $data = Json::decode($json);
     $releases = isset($data['packages'][$name]) ? $data['packages'][$name] : [];
     return compact('hash', 'releases', 'updateTime');
 }
 /**
  * Synchronizes file system packages to the database
  */
 public function actionSyncToDb()
 {
     $packages = $this->packageStorage->listPackages();
     foreach ($packages as $name => $data) {
         $message = "Package %N{$name}%n ";
         $package = AssetPackage::fromFullName($name);
         $package->load();
         $message .= $this->packageRepository->exists($package) ? 'already exists. %BUpdated.%n' : 'does not exist. %GCreated.%n';
         $this->packageRepository->save($package);
         $this->stdout(Console::renderColoredString($message . "\n"));
     }
 }
 public function actionUpdateList($file = STDIN)
 {
     $handler = is_resource($file) ? $file : fopen($file, 'r');
     $errorPackages = [];
     while ($line = fgets($handler)) {
         list($full) = preg_split('/\\s+/', trim($line));
         list($type, $name) = AssetPackage::splitFullName($full);
         if (!$this->actionUpdate($type, $name)) {
             $errorPackages[] = $full;
         }
     }
     if (!is_resource($file)) {
         fclose($handler);
     }
     if (!empty($errorPackages)) {
         echo Console::renderColoredString("%RThe following packages were not updated due to unrecoverable errors:%n\n");
         echo implode("\n", $errorPackages);
     }
     echo "\n";
 }
 public function run()
 {
     $this->beforeRun();
     $package = $this->package;
     $requires = [];
     foreach ($package->getReleases() as $release) {
         if (!isset($release['require'])) {
             continue;
         }
         foreach ($release['require'] as $name => $version) {
             $requires[$name] = true;
         }
     }
     foreach (array_keys($requires) as $name) {
         $assetPackage = AssetPackage::fromFullName($name);
         if ($this->packageRepository->exists($assetPackage)) {
             Yii::trace(Console::renderColoredString('Package %N' . $assetPackage->getFullName() . "%n already exists. Skipping.\n"), __CLASS__);
             continue;
         }
         Yii::$app->queue->push('package', Yii::createObject(PackageUpdateCommand::class, [$assetPackage]));
         Yii::trace(Console::renderColoredString('Created update command for %Y' . $assetPackage->getFullName() . "%n package\n"), __CLASS__);
     }
     $this->afterRun();
 }
 /**
  * Reloads package on wake up to ensure it is up to date
  *
  * @void
  */
 public function __wakeup()
 {
     $this->package->load();
     $this->packageRepository = Yii::createObject(PackageRepository::class);
 }
Esempio n. 7
0
 /**
  * @param $query
  * @return AssetPackage
  */
 private static function getAssetPackage($query)
 {
     $package = AssetPackage::fromFullName($query);
     $package->load();
     return $package;
 }
 public function testGetFullName()
 {
     $this->assertSame($this->type . '-asset/' . $this->name, $this->object->getFullName());
 }