Exemplo n.º 1
0
 /**
  * Protected constructor; use getInstance.
  */
 protected function __construct()
 {
     // Ensure implementing classes have necessary properties.
     if (!$this->name) {
         throw new \Exception('Missing name from ' . __CLASS__);
     }
     if (!$this->label) {
         throw new \Exception('Missing label from ' . __CLASS__);
     }
     if (!filter_var($this->homepage, FILTER_VALIDATE_URL)) {
         throw new \Exception('Missing valid homepage from ' . __CLASS__);
     }
     if (!filter_var($this->endpoint, FILTER_VALIDATE_URL)) {
         throw new \Exception('Missing valid endpoint from ' . __CLASS__);
     }
     if (drush_get_option('refresh')) {
         $this->apiGetSites();
     }
     $sites = SiteQuery::create()->filterByProvider($this->name)->find();
     if (!empty($sites)) {
         foreach ($sites as $site) {
             $this->sites[$site->getName()] = $site;
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param PropelPDO $con
  * @return void
  * @throws PropelException
  * @throws Exception
  * @see        BaseObject::setDeleted()
  * @see        BaseObject::isDeleted()
  */
 public function delete(PropelPDO $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getConnection(SitePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = SiteQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
Exemplo n.º 3
0
 /**
  * Returns a new SiteQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param   SiteQuery|Criteria $criteria Optional Criteria to build the query from
  *
  * @return SiteQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof SiteQuery) {
         return $criteria;
     }
     $query = new SiteQuery(null, null, $modelAlias);
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
Exemplo n.º 4
0
 /**
  * Get the associated Site object
  *
  * @param PropelPDO $con Optional Connection object.
  * @param $doQuery Executes a query to get the object if required
  * @return Site The associated Site object.
  * @throws PropelException
  */
 public function getSite(PropelPDO $con = null, $doQuery = true)
 {
     if ($this->aSite === null && $this->siteid !== null && $doQuery) {
         $this->aSite = SiteQuery::create()->findPk($this->siteid, $con);
         /* The following can be used additionally to
               guarantee the related object contains a reference
               to this object.  This level of coupling may, however, be
               undesirable since it could result in an only partially populated collection
               in the referenced object.
               $this->aSite->addEnvironments($this);
            */
     }
     return $this->aSite;
 }
Exemplo n.º 5
0
 /**
  * Helper function to get the S3 backup URL.
  *
  * @param string $site_name
  *   The machine name of the Site in question.
  * @param string $env_name
  *   The machine name of the Site Environment in question.
  * @param string $bucket
  *   The S3 bucket.
  * @param string $element
  *   Elements are db, code, files.
  *
  * @return string
  *   The S3 URL of the backup.
  */
 public function apiGetBackupDownloadUrl($site_name, $env_name, $bucket, $element)
 {
     $site = SiteQuery::create()->filterByProvider($this->name)->filterByName($site_name)->findOne();
     $result = switchboard_request($this, array('method' => 'POST', 'resource' => 'site', 'realm' => 'environments/' . $env_name . '/backups/catalog/' . $bucket . '/' . $element . '/s3token', 'uuid' => $site->getUuid(), 'data' => array('method' => 'GET')));
     $token = json_decode($result->body);
     return $token->url;
 }
Exemplo n.º 6
0
 /**
  * Helper function to get the latest database backup.
  *
  * @param string $site_name
  *   The machine name of the Site in question.
  * @param string $env_name
  *   The machine name of the Site Environment in question.
  * @param string $backup_type
  *   The type of backup.
  *
  * @return array
  *   A backup array as defined in apiGetSiteEnvBackups().
  */
 public function getSiteEnvBackupLatest($site_name, $env_name, $backup_type)
 {
     $site = SiteQuery::create()->filterByProvider($this->name)->filterByName($site_name)->findOne();
     $backup = parent::getSiteEnvBackupLatest($site_name, $env_name, $backup_type);
     if ($backup_type == 'db') {
         $backup['url'] = 'https://cloudapi.acquia.com/v1/sites/' . $site->getRealm() . ':' . $site_name . '/envs/' . $env_name . '/dbs/' . $site_name . '/backups/' . $backup['id'] . '/download.json';
     }
     unset($backup['id']);
     return $backup;
 }