public function testDoInsert() { try { $c = new Criteria(); $c->setPrimaryTableName(BookPeer::TABLE_NAME); $c->add(BookPeer::AUTHOR_ID, 'lkhlkhj'); BasePeer::doInsert($c, Propel::getConnection()); } catch (PropelException $e) { $this->assertContains('[INSERT INTO `book` (`AUTHOR_ID`) VALUES (:p1)]', $e->getMessage(), 'SQL query is written in the exception message'); } }
protected function insert($connection = null) { if (!isset($connection)) { $connection = QubitTransactionFilter::getConnection(QubitOaiHarvest::DATABASE_NAME); } $offset = 0; foreach ($this->tables as $table) { $criteria = new Criteria(); foreach ($table->getColumns() as $column) { if (!array_key_exists($column->getPhpName(), $this->values)) { if ('createdAt' == $column->getPhpName() || 'updatedAt' == $column->getPhpName()) { $this->values[$column->getPhpName()] = new DateTime(); } if ('sourceCulture' == $column->getPhpName()) { $this->values['sourceCulture'] = sfPropel::getDefaultCulture(); } } if (array_key_exists($column->getPhpName(), $this->values)) { if (null !== ($param = $this->param($column))) { $criteria->add($column->getFullyQualifiedName(), $param); } } $offset++; } if (null !== ($id = BasePeer::doInsert($criteria, $connection))) { // Guess that the first primary key of the first table is auto // incremented if ($this->tables[0] == $table) { $columns = $table->getPrimaryKeyColumns(); $this->values[$columns[0]->getPhpName()] = $this->keys[$columns[0]->getPhpName()] = $id; } } } return $this; }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $criteria = $this->buildCriteria(); $pk = BasePeer::doInsert($criteria, $con); $affectedRows = 1; $this->setNew(false); } else { $affectedRows = ReservationItemRightsPeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } $this->alreadyInSave = false; } return $affectedRows; }
/** * Performs an INSERT on the database, given a SubscriberGroupMembership or Criteria object. * * @param mixed $values Criteria or SubscriberGroupMembership object containing data that is used to create the INSERT statement. * @param PropelPDO $con the PropelPDO connection to use * @return mixed The new primary key. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doInsert($values, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(SubscriberGroupMembershipPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } if ($values instanceof Criteria) { $criteria = clone $values; // rename for clarity } else { $criteria = $values->buildCriteria(); // build Criteria from SubscriberGroupMembership object } // Set the correct dbName $criteria->setDbName(SubscriberGroupMembershipPeer::DATABASE_NAME); try { // use transaction because $criteria could contain info // for more than one table (I guess, conceivably) $con->beginTransaction(); $pk = BasePeer::doInsert($criteria, $con); $con->commit(); } catch (Exception $e) { $con->rollBack(); throw $e; } return $pk; }
/** * Method perform an INSERT on the database, given a MetadataProfile or Criteria object. * * @param mixed $values Criteria or MetadataProfile object containing data that is used to create the INSERT statement. * @param PropelPDO $con the PropelPDO connection to use * @return mixed The new primary key. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doInsert($values, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(MetadataProfilePeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } if ($values instanceof Criteria) { $criteria = clone $values; // rename for clarity } else { $criteria = $values->buildCriteria(); // build Criteria from MetadataProfile object } if ($criteria->containsKey(MetadataProfilePeer::ID) && $criteria->keyContainsValue(MetadataProfilePeer::ID)) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . MetadataProfilePeer::ID . ')'); } // Set the correct dbName $criteria->setDbName(self::DATABASE_NAME); try { // use transaction because $criteria could contain info // for more than one table (I guess, conceivably) $con->beginTransaction(); $pk = BasePeer::doInsert($criteria, $con); $con->commit(); } catch (PropelException $e) { $con->rollBack(); throw $e; } return $pk; }
/** * Method perform an INSERT on the database, given a ExamCommentDig or Criteria object. * * @param mixed $values Criteria or ExamCommentDig object containing data that is used to create the INSERT statement. * @param PropelPDO $con the PropelPDO connection to use * @return mixed The new primary key. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doInsert($values, PropelPDO $con = null) { foreach (sfMixer::getCallables('BaseExamCommentDigPeer:doInsert:pre') as $callable) { $ret = call_user_func($callable, 'BaseExamCommentDigPeer', $values, $con); if (false !== $ret) { return $ret; } } if ($con === null) { $con = Propel::getConnection(ExamCommentDigPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } if ($values instanceof Criteria) { $criteria = clone $values; // rename for clarity } else { $criteria = $values->buildCriteria(); // build Criteria from ExamCommentDig object } // Set the correct dbName $criteria->setDbName(self::DATABASE_NAME); try { // use transaction because $criteria could contain info // for more than one table (I guess, conceivably) $con->beginTransaction(); $pk = BasePeer::doInsert($criteria, $con); $con->commit(); } catch (PropelException $e) { $con->rollBack(); throw $e; } foreach (sfMixer::getCallables('BaseExamCommentDigPeer:doInsert:post') as $callable) { call_user_func($callable, 'BaseExamCommentDigPeer', $values, $con, $pk); } return $pk; }
/** * Method perform an INSERT on the database, given a UserStatEquip or Criteria object. * * @param mixed $values Criteria or UserStatEquip object containing data that is used to create the INSERT statement. * @param PropelPDO $con the PropelPDO connection to use * @return mixed The new primary key. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doInsert($values, PropelPDO $con = null) { foreach (sfMixer::getCallables('BaseUserStatEquipPeer:doInsert:pre') as $callable) { $ret = call_user_func($callable, 'BaseUserStatEquipPeer', $values, $con); if (false !== $ret) { return $ret; } } if ($con === null) { $con = Propel::getConnection(UserStatEquipPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } if ($values instanceof Criteria) { $criteria = clone $values; // rename for clarity } else { $criteria = $values->buildCriteria(); // build Criteria from UserStatEquip object } if ($criteria->containsKey(UserStatEquipPeer::USER_STAT_EQUIP_ID) && $criteria->keyContainsValue(UserStatEquipPeer::USER_STAT_EQUIP_ID)) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . UserStatEquipPeer::USER_STAT_EQUIP_ID . ')'); } // Set the correct dbName $criteria->setDbName(self::DATABASE_NAME); try { // use transaction because $criteria could contain info // for more than one table (I guess, conceivably) $con->beginTransaction(); $pk = BasePeer::doInsert($criteria, $con); $con->commit(); } catch (PropelException $e) { $con->rollBack(); throw $e; } foreach (sfMixer::getCallables('BaseUserStatEquipPeer:doInsert:post') as $callable) { call_user_func($callable, 'BaseUserStatEquipPeer', $values, $con, $pk); } return $pk; }
/** * Method perform an INSERT on the database, given a PcBlogComment or Criteria object. * * @param mixed $values Criteria or PcBlogComment object containing data that is used to create the INSERT statement. * @param PropelPDO $con the PropelPDO connection to use * @return mixed The new primary key. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doInsert($values, PropelPDO $con = null) { // symfony_behaviors behavior foreach (sfMixer::getCallables('BasePcBlogCommentPeer:doInsert:pre') as $sf_hook) { if (false !== ($sf_hook_retval = call_user_func($sf_hook, 'BasePcBlogCommentPeer', $values, $con))) { return $sf_hook_retval; } } if ($con === null) { $con = Propel::getConnection(PcBlogCommentPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } if ($values instanceof Criteria) { $criteria = clone $values; // rename for clarity } else { $criteria = $values->buildCriteria(); // build Criteria from PcBlogComment object } if ($criteria->containsKey(PcBlogCommentPeer::ID) && $criteria->keyContainsValue(PcBlogCommentPeer::ID)) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . PcBlogCommentPeer::ID . ')'); } // Set the correct dbName $criteria->setDbName(self::DATABASE_NAME); try { // use transaction because $criteria could contain info // for more than one table (I guess, conceivably) $con->beginTransaction(); $pk = BasePeer::doInsert($criteria, $con); $con->commit(); } catch (PropelException $e) { $con->rollBack(); throw $e; } // symfony_behaviors behavior foreach (sfMixer::getCallables('BasePcBlogCommentPeer:doInsert:post') as $sf_hook) { call_user_func($sf_hook, 'BasePcBlogCommentPeer', $values, $con, $pk); } return $pk; }
public static function doInsert($values, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(RelAnioActividadDocentePeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } if ($values instanceof Criteria) { $criteria = clone $values; } else { $criteria = $values->buildCriteria(); } $criteria->setDbName(self::DATABASE_NAME); try { $con->beginTransaction(); $pk = BasePeer::doInsert($criteria, $con); $con->commit(); } catch (PropelException $e) { $con->rollBack(); throw $e; } return $pk; }
/** * Method perform an INSERT on the database, given a SchemaPropertyElementHistory or Criteria object. * * @param mixed $values Criteria or SchemaPropertyElementHistory object containing data that is used to create the INSERT statement. * @param Connection $con the connection to use * @return mixed The new primary key. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doInsert($values, $con = null) { foreach (sfMixer::getCallables('BaseSchemaPropertyElementHistoryPeer:doInsert:pre') as $callable) { $ret = call_user_func($callable, 'BaseSchemaPropertyElementHistoryPeer', $values, $con); if (false !== $ret) { return $ret; } } if ($con === null) { $con = Propel::getConnection(self::DATABASE_NAME); } if ($values instanceof Criteria) { $criteria = clone $values; // rename for clarity } else { $criteria = $values->buildCriteria(); // build Criteria from SchemaPropertyElementHistory object } $criteria->remove(SchemaPropertyElementHistoryPeer::ID); // remove pkey col since this table uses auto-increment // Set the correct dbName $criteria->setDbName(self::DATABASE_NAME); try { // use transaction because $criteria could contain info // for more than one table (I guess, conceivably) $con->begin(); $pk = BasePeer::doInsert($criteria, $con); $con->commit(); } catch (PropelException $e) { $con->rollback(); throw $e; } foreach (sfMixer::getCallables('BaseSchemaPropertyElementHistoryPeer:doInsert:post') as $callable) { call_user_func($callable, 'BaseSchemaPropertyElementHistoryPeer', $values, $con, $pk); } return $pk; }
public static function doInsert($values, PropelPDO $con = null) { foreach (sfMixer::getCallables('BaseProductPeer:doInsert:pre') as $callable) { $ret = call_user_func($callable, 'BaseProductPeer', $values, $con); if (false !== $ret) { return $ret; } } if ($con === null) { $con = Propel::getConnection(ProductPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } if ($values instanceof Criteria) { $criteria = clone $values; } else { $criteria = $values->buildCriteria(); } if ($criteria->containsKey(ProductPeer::ID) && $criteria->keyContainsValue(ProductPeer::ID)) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . ProductPeer::ID . ')'); } $criteria->setDbName(self::DATABASE_NAME); try { $con->beginTransaction(); $pk = BasePeer::doInsert($criteria, $con); $con->commit(); } catch (PropelException $e) { $con->rollBack(); throw $e; } foreach (sfMixer::getCallables('BaseProductPeer:doInsert:post') as $callable) { call_user_func($callable, 'BaseProductPeer', $values, $con, $pk); } return $pk; }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $criteria = $this->buildCriteria(); $pk = BasePeer::doInsert($criteria, $con); $affectedRows = 1; $this->setNew(false); } else { $affectedRows = ResponsableEleveAdressePeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } if ($this->collResponsableEleves !== null) { foreach ($this->collResponsableEleves as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collAbsenceEleveNotifications !== null) { foreach ($this->collAbsenceEleveNotifications as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } $this->alreadyInSave = false; } return $affectedRows; } // doSave()
/** * Import data into table from CSV file. * * @todo Add support for propel advanced columns (array). * * @throws Exception */ public function showImport() { $modelClass = $_GET['table']; $tableMap = PropelQuery::from($modelClass)->getTableMap(); $columnOptions = Curry_Array::objectsToArray($tableMap->getColumns(), 'getName', 'getPhpName'); $pks = array(); foreach ($tableMap->getColumns() as $column) { if ($column->isPrimaryKey()) { $pks[] = $column->getName(); } } $form = new Curry_Form(array('method' => 'post', 'action' => url('', $_GET), 'elements' => array('file' => array('file', array('label' => 'CSV File', 'valueDisabled' => true)), 'mode' => array('select', array('label' => 'Mode', 'multiOptions' => array(self::IMPORT_REPLACE => 'Replace', self::IMPORT_APPEND => 'Append', self::IMPORT_UPDATE => 'Update', self::IMPORT_UPDATE_OR_INSERT => 'Update or insert'))), 'skip_first' => array('checkbox', array('label' => 'Skip first line', 'value' => true)), 'columns' => array('text', array('label' => 'Columns in file', 'value' => join(',', array_keys($columnOptions)))), 'use_columns' => array('multiselect', array('label' => 'Columns to use', 'multiOptions' => $columnOptions, 'value' => array_keys($columnOptions), 'size' => min(10, count($columnOptions)))), 'delimiter' => array('text', array('label' => 'Delimiter', 'value' => ',')), 'enclosure' => array('text', array('label' => 'Enclosure', 'value' => '"')), 'escape' => array('text', array('label' => 'Escape', 'value' => '\\')), 'null_value' => array('text', array('label' => 'Null', 'value' => 'Ø')), 'submit' => array('submit', array('label' => 'Import'))))); $fields = array_slice(array_keys($form->getElements()), 2, -1); $form->addDisplayGroup($fields, 'advanced', array('legend' => 'Advanced options', 'class' => 'advanced', 'order' => 2)); $this->addMainContent('<h2>Import: ' . htmlspecialchars($modelClass) . '</h2>'); if (isPost() && $form->isValid($_POST)) { $mode = $form->mode->getValue(); $skipFirst = $form->skip_first->getValue(); $columns = explode(',', $form->columns->getValue()); $useColumns = $form->use_columns->getValue(); $delimiter = $form->delimiter->getValue(); $enclosure = $form->enclosure->getValue(); $escape = $form->escape->getValue(); $nullValue = $form->null_value->getValue(); if (!$form->file->isUploaded()) { throw new Exception('Error when uploading file.'); } // Check for non-existent columns $nonExistent = array_filter(array_diff($columns, array_keys($columnOptions))); if (count($nonExistent)) { throw new Exception('Unknown column in column list: ' . join(', ', $nonExistent)); } // Open csv file $fileInfo = $form->file->getFileInfo(); $fp = fopen($fileInfo['file']['tmp_name'], "r"); if (!$fp) { throw new Exception('Unable to open file'); } // Wrap in transaction $deleted = 0; $updated = 0; $inserted = 0; $con = Propel::getConnection(PropelQuery::from($modelClass)->getDbName()); $con->beginTransaction(); try { // Replace will empty the table if ($mode === self::IMPORT_REPLACE) { $deleted = PropelQuery::from($modelClass)->deleteAll(); } // Read csv lines while (($data = fgetcsv($fp, 0, $delimiter, $enclosure, $escape)) !== false) { if (count($data) !== count($columns)) { throw new Exception('Invalid column count ' . count($data) . ', expected ' . count($columns)); } if ($skipFirst) { $skipFirst = false; continue; } $data = array_combine($columns, $data); $pkData = array(); // Check for null values and collect primary key foreach ($data as $k => $v) { if ($v === $nullValue) { $data[$k] = $v = null; } if (in_array($k, $pks)) { $pkData[$k] = $v; } } $obj = null; if ($mode === self::IMPORT_UPDATE || $mode === self::IMPORT_UPDATE_OR_INSERT) { // attempt to find existing object using pk if (count($pkData) === count($pks)) { $obj = new $modelClass(); $obj->fromArray($pkData, BasePeer::TYPE_FIELDNAME); $obj = PropelQuery::from($modelClass)->findPk($obj->getPrimaryKey()); } if (!$obj && $mode === self::IMPORT_UPDATE_OR_INSERT) { // not found, create new $obj = new $modelClass(); } } else { // REPLACE, APPEND $obj = new $modelClass(); } // Remove unused columns foreach ($data as $k => $v) { if (!in_array($k, $useColumns)) { unset($data[$k]); } } if ($obj) { // Unset primary key columns in data when appending if ($mode === self::IMPORT_APPEND) { foreach ($pks as $pk) { if (array_key_exists($pk, $data)) { unset($data[$pk]); } } } $obj->fromArray($data, BasePeer::TYPE_FIELDNAME); if ($obj->isNew()) { // allows insert of custom primary key BasePeer::doInsert($obj->buildCriteria(), $con); ++$inserted; } else { $updated += $obj->save(); } } } $con->commit(); } catch (Exception $e) { $con->rollBack(); throw $e; } if ($deleted) { $this->addMessage('Deleted: ' . $deleted); } if ($inserted) { $this->addMessage('Inserted: ' . $inserted); } if ($updated) { $this->addMessage('Updated: ' . $updated); } $this->addMessage('All done.', self::MSG_SUCCESS); } else { $this->addMainContent($form); } }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; if ($this->isNew()) { $this->modifiedColumns[] = OpenidAssociationPeer::ID; } // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $criteria = $this->buildCriteria(); if ($criteria->keyContainsValue(OpenidAssociationPeer::ID)) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . OpenidAssociationPeer::ID . ')'); } $pk = BasePeer::doInsert($criteria, $con); $affectedRows = 1; $this->setId($pk); //[IMV] update autoincrement primary key $this->setNew(false); } else { $affectedRows = OpenidAssociationPeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } $this->alreadyInSave = false; } return $affectedRows; }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aGroup !== null) { if ($this->aGroup->isModified() || $this->aGroup->isNew()) { $affectedRows += $this->aGroup->save($con); } $this->setGroup($this->aGroup); } if ($this->aUser !== null) { if ($this->aUser->isModified() || $this->aUser->isNew()) { $affectedRows += $this->aUser->save($con); } $this->setUser($this->aUser); } if ($this->isNew()) { $this->modifiedColumns[] = DirectoryPermissionPeer::ID; } // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $criteria = $this->buildCriteria(); if ($criteria->keyContainsValue(DirectoryPermissionPeer::ID)) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . DirectoryPermissionPeer::ID . ')'); } $pk = BasePeer::doInsert($criteria, $con); $affectedRows += 1; $this->setId($pk); //[IMV] update autoincrement primary key $this->setNew(false); } else { $affectedRows += DirectoryPermissionPeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } $this->alreadyInSave = false; } return $affectedRows; }
public static function doInsert($values, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(TipodocentePeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } if ($values instanceof Criteria) { $criteria = clone $values; } else { $criteria = $values->buildCriteria(); } if ($criteria->containsKey(TipodocentePeer::ID) && $criteria->keyContainsValue(TipodocentePeer::ID)) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . TipodocentePeer::ID . ')'); } $criteria->setDbName(self::DATABASE_NAME); try { $con->beginTransaction(); $pk = BasePeer::doInsert($criteria, $con); $con->commit(); } catch (PropelException $e) { $con->rollBack(); throw $e; } return $pk; }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aCcShow !== null) { if ($this->aCcShow->isModified() || $this->aCcShow->isNew()) { $affectedRows += $this->aCcShow->save($con); } $this->setCcShow($this->aCcShow); } if ($this->aCcShowInstancesRelatedByDbOriginalShow !== null) { if ($this->aCcShowInstancesRelatedByDbOriginalShow->isModified() || $this->aCcShowInstancesRelatedByDbOriginalShow->isNew()) { $affectedRows += $this->aCcShowInstancesRelatedByDbOriginalShow->save($con); } $this->setCcShowInstancesRelatedByDbOriginalShow($this->aCcShowInstancesRelatedByDbOriginalShow); } if ($this->aCcFiles !== null) { if ($this->aCcFiles->isModified() || $this->aCcFiles->isNew()) { $affectedRows += $this->aCcFiles->save($con); } $this->setCcFiles($this->aCcFiles); } if ($this->isNew()) { $this->modifiedColumns[] = CcShowInstancesPeer::ID; } // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $criteria = $this->buildCriteria(); if ($criteria->keyContainsValue(CcShowInstancesPeer::ID)) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . CcShowInstancesPeer::ID . ')'); } $pk = BasePeer::doInsert($criteria, $con); $affectedRows += 1; $this->setDbId($pk); //[IMV] update autoincrement primary key $this->setNew(false); } else { $affectedRows += CcShowInstancesPeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } if ($this->collCcShowInstancessRelatedByDbId !== null) { foreach ($this->collCcShowInstancessRelatedByDbId as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collCcSchedules !== null) { foreach ($this->collCcSchedules as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } $this->alreadyInSave = false; } return $affectedRows; }
public static function doInsert($values, $con = null) { foreach (sfMixer::getCallables('BasenahoWikiPagePeer:doInsert:pre') as $callable) { $ret = call_user_func($callable, 'BasenahoWikiPagePeer', $values, $con); if (false !== $ret) { return $ret; } } if ($con === null) { $con = Propel::getConnection(self::DATABASE_NAME); } if ($values instanceof Criteria) { $criteria = clone $values; } else { $criteria = $values->buildCriteria(); } $criteria->remove(nahoWikiPagePeer::ID); $criteria->setDbName(self::DATABASE_NAME); try { $con->begin(); $pk = BasePeer::doInsert($criteria, $con); $con->commit(); } catch (PropelException $e) { $con->rollback(); throw $e; } foreach (sfMixer::getCallables('BasenahoWikiPagePeer:doInsert:post') as $callable) { call_user_func($callable, 'BasenahoWikiPagePeer', $values, $con, $pk); } return $pk; }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aCcSubjs !== null) { if ($this->aCcSubjs->isModified() || $this->aCcSubjs->isNew()) { $affectedRows += $this->aCcSubjs->save($con); } $this->setCcSubjs($this->aCcSubjs); } // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $criteria = $this->buildCriteria(); $pk = BasePeer::doInsert($criteria, $con); $affectedRows += 1; $this->setNew(false); } else { $affectedRows += CcSessPeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } $this->alreadyInSave = false; } return $affectedRows; }
/** * Method perform an INSERT on the database, given a BpmnProject or Criteria object. * * @param mixed $values Criteria or BpmnProject object containing data that is used to create the INSERT statement. * @param Connection $con the connection to use * @return mixed The new primary key. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doInsert($values, $con = null) { if ($con === null) { $con = Propel::getConnection(self::DATABASE_NAME); } if ($values instanceof Criteria) { $criteria = clone $values; // rename for clarity } else { $criteria = $values->buildCriteria(); // build Criteria from BpmnProject object } // Set the correct dbName $criteria->setDbName(self::DATABASE_NAME); try { // use transaction because $criteria could contain info // for more than one table (I guess, conceivably) $con->begin(); $pk = BasePeer::doInsert($criteria, $con); $con->commit(); } catch (PropelException $e) { $con->rollback(); throw $e; } return $pk; }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; if ($this->isNew()) { $this->modifiedColumns[] = CcSubjsPeer::ID; } // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $criteria = $this->buildCriteria(); if ($criteria->keyContainsValue(CcSubjsPeer::ID)) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . CcSubjsPeer::ID . ')'); } $pk = BasePeer::doInsert($criteria, $con); $affectedRows = 1; $this->setDbId($pk); //[IMV] update autoincrement primary key $this->setNew(false); } else { $affectedRows = CcSubjsPeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } if ($this->collCcAccesss !== null) { foreach ($this->collCcAccesss as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collCcFiless !== null) { foreach ($this->collCcFiless as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collCcPermss !== null) { foreach ($this->collCcPermss as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collCcShowHostss !== null) { foreach ($this->collCcShowHostss as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collCcPlaylists !== null) { foreach ($this->collCcPlaylists as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collCcPrefs !== null) { foreach ($this->collCcPrefs as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collCcSesss !== null) { foreach ($this->collCcSesss as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collCcSubjsTokens !== null) { foreach ($this->collCcSubjsTokens as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } $this->alreadyInSave = false; } return $affectedRows; }
public static function doInsert($values, $con = null) { if ($con === null) { $con = Propel::getConnection(self::DATABASE_NAME); } if ($values instanceof Criteria) { $criteria = clone $values; } else { $criteria = $values->buildCriteria(); } $criteria->remove(LorfieldsPeer::ID); $criteria->setDbName(self::DATABASE_NAME); try { $con->begin(); $pk = BasePeer::doInsert($criteria, $con); $con->commit(); } catch (PropelException $e) { $con->rollback(); throw $e; } return $pk; }
} $key = ""; for ($i = 0; $i < $length; $i++) { $key .= $charset[mt_rand(0, strlen($charset) - 1)]; } return md5($key); } $partner = new Partner(); $partner->setId(-3); $partner->setPartnerName('Hosted Pages'); $partner->setPartnerAlias('Hosted Pages'); $partner->setDescription('Build-in partner - used for hosted pages'); $partner->setSecret(generateSecret()); $partner->setAdminSecret(generateSecret()); $partner->setMaxNumberOfHitsPerDay(-1); $partner->setAppearInSearch(mySearchUtils::DISPLAY_IN_SEARCH_NONE); $partner->setInvalidLoginCount(0); $partner->setKsMaxExpiryInSeconds(86400); $partner->setCreateUserOnDemand(false); $partner->setCommercialUse(false); $partner->setModerateContent(false); $partner->setNotify(false); $partner->setIsFirstLogin(true); $partner->setAdminLoginUsersQuota(0); $partner->setStatus(Partner::PARTNER_STATUS_ACTIVE); $partner->setType(PartnerGroupType::PUBLISHER); $criteria = $partner->buildCriteria(); $criteria->setDbName(PartnerPeer::DATABASE_NAME); $con = Propel::getConnection(PartnerPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); $id = BasePeer::doInsert($criteria, $con); echo "Created partner [{$id}]\n";