hiqdev\assetpackagist\repositories\PackageRepository::exists PHP Method

exists() public method

public exists ( AssetPackage $package ) : boolean
$package hiqdev\assetpackagist\models\AssetPackage
return boolean
    public function exists(AssetPackage $package)
    {
        return (new Query())->from('package')->where(['type' => $package->getType(), 'name' => $package->getName()])->exists($this->db);
    }

Usage Example

 /**
  * 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"));
     }
 }