/** * Commits changes (increases serial by 1) * * @return Array on success, string on error */ public static function commit() { // do some checks first $pdns_version = trim(shell_exec("sudo /usr/bin/pdns_control version 2>&1")); if (!preg_match('/^[0-9,\\.]+$/', $pdns_version)) { if (preg_match('/\\[sudo\\] password/', $pdns_version)) { return "Unable to run 'sudo /usr/bin/pdns_control'. Is it defined in sudoers file?"; } else { return $pdns_version; } } $commited = array(); $c = new Criteria(); $c->add(AuditPeer::OBJECT, 'Record'); $c->addGroupByColumn(AuditPeer::DOMAIN_ID); $c->add(AuditPeer::CREATED_AT, date("Y-m-d H:i:s", MyTools::getLastCommit()), Criteria::GREATER_THAN); foreach (AuditPeer::doSelect($c) as $audit) { $domain = DomainPeer::retrieveByPK($audit->getDomainId()); $commited[] = $domain->getName(); // get SOA record $c = new Criteria(); $c->add(RecordPeer::DOMAIN_ID, $domain->getId()); $c->add(RecordPeer::TYPE, 'SOA'); $SOA = RecordPeer::doSelectOne($c); $temp = explode(" ", $SOA->getContent()); $serial = $temp[2]; $date = substr($serial, 0, 8); $id = substr($serial, 8); // today ? if ($date == date("Ymd")) { $id++; if (strlen($id) == 1) { $id = "0" . $id; } $serial = $date . $id; } else { $serial = date("Ymd") . "01"; } if ($serial >= 4294967295) { continue; } // don't allow >= 32bit unsigned $SOA->setContent(implode(" ", array($temp[0], $temp[1], $serial))); $SOA->save(); } if ($commited) { SettingPeer::setValue('last_commit', time()); sleep(2); if ($also_notify = sfConfig::get('app_default_also-notify')) { foreach ($commited as $domain) { foreach ($also_notify as $host) { exec("sudo /usr/bin/pdns_control notify-host {$domain} {$host}"); } } } } return $commited; }
public function getDomain($con = null) { if ($this->aDomain === null && $this->domain_id !== null) { include_once 'lib/model/om/BaseDomainPeer.php'; $this->aDomain = DomainPeer::retrieveByPK($this->domain_id, $con); } return $this->aDomain; }
public function validateDelete() { if (!($this->domain = DomainPeer::retrieveByPK($this->getRequestParameter('id')))) { $this->getRequest()->setError('id', 'Invalid domain id'); return false; } return true; }
/** * Selects a collection of PropertyValue objects pre-filled with all related objects except User. * * @param Criteria $criteria * @param PropelPDO $con * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN * @return array Array of PropertyValue objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAllExceptUser(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $criteria = clone $criteria; // Set the correct dbName if it has not been overridden // $criteria->getDbName() will return the same object if not set to another value // so == check is okay and faster if ($criteria->getDbName() == Propel::getDefaultDB()) { $criteria->setDbName(PropertyValuePeer::DATABASE_NAME); } PropertyValuePeer::addSelectColumns($criteria); $startcol2 = PropertyValuePeer::NUM_HYDRATE_COLUMNS; DomainPeer::addSelectColumns($criteria); $startcol3 = $startcol2 + DomainPeer::NUM_HYDRATE_COLUMNS; PropertyPeer::addSelectColumns($criteria); $startcol4 = $startcol3 + PropertyPeer::NUM_HYDRATE_COLUMNS; $criteria->addJoin(PropertyValuePeer::DOMAIN_ID, DomainPeer::ID, $join_behavior); $criteria->addJoin(PropertyValuePeer::PROPERTY_ID, PropertyPeer::ID, $join_behavior); $stmt = BasePeer::doSelect($criteria, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = PropertyValuePeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = PropertyValuePeer::getInstanceFromPool($key1))) { // We no longer rehydrate the object, since this can cause data loss. // See http://www.propelorm.org/ticket/509 // $obj1->hydrate($row, 0, true); // rehydrate } else { $cls = PropertyValuePeer::getOMClass(); $obj1 = new $cls(); $obj1->hydrate($row); PropertyValuePeer::addInstanceToPool($obj1, $key1); } // if obj1 already loaded // Add objects for joined Domain rows $key2 = DomainPeer::getPrimaryKeyHashFromRow($row, $startcol2); if ($key2 !== null) { $obj2 = DomainPeer::getInstanceFromPool($key2); if (!$obj2) { $cls = DomainPeer::getOMClass(); $obj2 = new $cls(); $obj2->hydrate($row, $startcol2); DomainPeer::addInstanceToPool($obj2, $key2); } // if $obj2 already loaded // Add the $obj1 (PropertyValue) to the collection in $obj2 (Domain) $obj2->addPropertyValue($obj1); } // if joined row is not null // Add objects for joined Property rows $key3 = PropertyPeer::getPrimaryKeyHashFromRow($row, $startcol3); if ($key3 !== null) { $obj3 = PropertyPeer::getInstanceFromPool($key3); if (!$obj3) { $cls = PropertyPeer::getOMClass(); $obj3 = new $cls(); $obj3->hydrate($row, $startcol3); PropertyPeer::addInstanceToPool($obj3, $key3); } // if $obj3 already loaded // Add the $obj1 (PropertyValue) to the collection in $obj3 (Property) $obj3->addPropertyValue($obj1); } // if joined row is not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }
public static function retrieveByPKs($pks, $con = null) { if ($con === null) { $con = Propel::getConnection(self::DATABASE_NAME); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(); $criteria->add(DomainPeer::ID, $pks, Criteria::IN); $objs = DomainPeer::doSelect($criteria, $con); } return $objs; }
/** * Find object by primary key using raw SQL to go fast. * Bypass doSelect() and the object formatter by using generated code. * * @param mixed $key Primary key to use for the query * @param PropelPDO $con A connection object * * @return Domain A model object, or null if the key is not found * @throws PropelException */ protected function findPkSimple($key, $con) { $sql = 'SELECT `id`, `account_id`, `address_id`, `name`, `valid`, `description`, `number` FROM `domain` WHERE `id` = :p0'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key, PDO::PARAM_INT); $stmt->execute(); } catch (Exception $e) { Propel::log($e->getMessage(), Propel::LOG_ERR); throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), $e); } $obj = null; if ($row = $stmt->fetch(PDO::FETCH_NUM)) { $obj = new Domain(); $obj->hydrate($row); DomainPeer::addInstanceToPool($obj, (string) $key); } $stmt->closeCursor(); return $obj; }
/** * This is a method for emulating ON DELETE CASCADE for DBs that don't support this * feature (like MySQL or SQLite). * * This method is not very speedy because it must perform a query first to get * the implicated records and then perform the deletes by calling those Peer classes. * * This method should be used within a transaction if possible. * * @param Criteria $criteria * @param PropelPDO $con * @return int The number of affected rows (if supported by underlying database driver). */ protected static function doOnDeleteCascade(Criteria $criteria, PropelPDO $con) { // initialize var to track total num of affected rows $affectedRows = 0; // first find the objects that are implicated by the $criteria $objects = AccountPeer::doSelect($criteria, $con); foreach ($objects as $obj) { // delete related BookingType objects $criteria = new Criteria(BookingTypePeer::DATABASE_NAME); $criteria->add(BookingTypePeer::ACCOUNT_ID, $obj->getId()); $affectedRows += BookingTypePeer::doDelete($criteria, $con); // delete related ClockingType objects $criteria = new Criteria(ClockingTypePeer::DATABASE_NAME); $criteria->add(ClockingTypePeer::ACCOUNT_ID, $obj->getId()); $affectedRows += ClockingTypePeer::doDelete($criteria, $con); // delete related Domain objects $criteria = new Criteria(DomainPeer::DATABASE_NAME); $criteria->add(DomainPeer::ACCOUNT_ID, $obj->getId()); $affectedRows += DomainPeer::doDelete($criteria, $con); // delete related Holiday objects $criteria = new Criteria(HolidayPeer::DATABASE_NAME); $criteria->add(HolidayPeer::ACCOUNT_ID, $obj->getId()); $affectedRows += HolidayPeer::doDelete($criteria, $con); // delete related Plugin objects $criteria = new Criteria(PluginPeer::DATABASE_NAME); $criteria->add(PluginPeer::ACCOUNT_ID, $obj->getId()); $affectedRows += PluginPeer::doDelete($criteria, $con); // delete related Property objects $criteria = new Criteria(PropertyPeer::DATABASE_NAME); $criteria->add(PropertyPeer::ACCOUNT_ID, $obj->getId()); $affectedRows += PropertyPeer::doDelete($criteria, $con); // delete related User objects $criteria = new Criteria(UserPeer::DATABASE_NAME); $criteria->add(UserPeer::ACCOUNT_ID, $obj->getId()); $affectedRows += UserPeer::doDelete($criteria, $con); } return $affectedRows; }
public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = DomainPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setName($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setMaster($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setLastCheck($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setType($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setNotifiedSerial($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setAccount($arr[$keys[6]]); } }
/** * Populates the object using an array. * * This is particularly useful when populating an object from one of the * request arrays (e.g. $_POST). This method goes through the column * names, checking to see whether a matching key exists in populated * array. If so the setByName() method is called for that column. * * You can specify the key type of the array by additionally passing one * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. * The default key type is the column's BasePeer::TYPE_PHPNAME * * @param array $arr An array to populate the object from. * @param string $keyType The type of keys the array uses. * @return void */ public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = DomainPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setAccountId($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setAddressId($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setName($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setValid($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setDescription($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setNumber($arr[$keys[6]]); } }
public static function doSelectJoinAll(Criteria $c, $con = null) { foreach (sfMixer::getCallables('BaseRecordPeer:doSelectJoinAll:doSelectJoinAll') as $callable) { call_user_func($callable, 'BaseRecordPeer', $c, $con); } $c = clone $c; if ($c->getDbName() == Propel::getDefaultDB()) { $c->setDbName(self::DATABASE_NAME); } RecordPeer::addSelectColumns($c); $startcol2 = RecordPeer::NUM_COLUMNS - RecordPeer::NUM_LAZY_LOAD_COLUMNS + 1; DomainPeer::addSelectColumns($c); $startcol3 = $startcol2 + DomainPeer::NUM_COLUMNS; $c->addJoin(RecordPeer::DOMAIN_ID, DomainPeer::ID); $rs = BasePeer::doSelect($c, $con); $results = array(); while ($rs->next()) { $omClass = RecordPeer::getOMClass(); $cls = Propel::import($omClass); $obj1 = new $cls(); $obj1->hydrate($rs); $omClass = DomainPeer::getOMClass(); $cls = Propel::import($omClass); $obj2 = new $cls(); $obj2->hydrate($rs, $startcol2); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj2 = $temp_obj1->getDomain(); if ($temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey()) { $newObject = false; $temp_obj2->addRecord($obj1); break; } } if ($newObject) { $obj2->initRecords(); $obj2->addRecord($obj1); } $results[] = $obj1; } return $results; }