public static function doBackupRecord(\Criteria $criteria, PropelPDO $con)
 {
     $db = Propel::getDB($criteria->getDbName());
     $dbMap = Propel::getDatabaseMap($criteria->getDbName());
     $keys = $criteria->keys();
     if (!empty($keys)) {
         $tableName = $criteria->getTableName($keys[0]);
     } else {
         throw new PropelException("Database insert attempted without anything specified to insert");
     }
     $tableMap = $dbMap->getTable($tableName);
     $whereClause = array();
     $peer = $tableMap->getPeerClassname();
     $versionTable = $peer::$workspaceBehaviorVersionName;
     $originTable = $tableMap->getName();
     $tables = $criteria->getTablesColumns();
     if (empty($tables)) {
         throw new \PropelException("Empty Criteria");
     }
     $fields = array_keys($tableMap->getColumns());
     $fields = implode(', ', $fields);
     foreach ($tables as $tableName => $columns) {
         $whereClause = array();
         $params = array();
         $stmt = null;
         try {
             foreach ($columns as $colName) {
                 $sb = "";
                 $criteria->getCriterion($colName)->appendPsTo($sb, $params);
                 $whereClause[] = $sb;
             }
             $sql = sprintf("INSERT INTO %s (%s) SELECT %s FROM %s WHERE %s", $versionTable, $fields, $fields, $originTable, implode(" AND ", $whereClause));
             $stmt = $con->prepare($sql);
             $db->bindValues($stmt, $params, $dbMap);
             $stmt->execute();
             $stmt->closeCursor();
         } catch (Exception $e) {
             Propel::log($e->getMessage(), Propel::LOG_ERR);
             throw new PropelException(sprintf('Unable to execute INSERT INTO statement [%s]', $sql), $e);
         }
     }
     // for each table
 }
Example #2
0
 /**
  * Helper method which returns the primary key contained
  * in the given Criteria object.
  *
  * @param      Criteria $criteria A Criteria.
  * @return     ColumnMap If the Criteria object contains a primary
  *		  key, or null if it doesn't.
  * @throws     PropelException
  */
 private static function getPrimaryKey(Criteria $criteria)
 {
     // Assume all the keys are for the same table.
     $keys = $criteria->keys();
     $key = $keys[0];
     $table = $criteria->getTableName($key);
     $pk = null;
     if (!empty($table)) {
         $dbMap = Propel::getDatabaseMap($criteria->getDbName());
         $pks = $dbMap->getTable($table)->getPrimaryKeys();
         if (!empty($pks)) {
             $pk = array_shift($pks);
         }
     }
     return $pk;
 }
 /**
  * Helper method which returns the primary key contained
  * in the given Criteria object.
  *
  * @param Criteria $criteria A Criteria.
  * @return ColumnMap If the Criteria object contains a primary
  *		  key, or null if it doesn't.
  * @throws PropelException
  */
 private static function getPrimaryKey(Criteria $criteria)
 {
     // Assume all the keys are for the same table.
     $keys = $criteria->keys();
     $key = $keys[0];
     $table = $criteria->getTableName($key);
     $pk = null;
     if (!empty($table)) {
         $dbMap = Propel::getDatabaseMap($criteria->getDbName());
         if ($dbMap === null) {
             throw new PropelException("\$dbMap is null");
         }
         if ($dbMap->getTable($table) === null) {
             throw new PropelException("\$dbMap->getTable() is null");
         }
         $columns = $dbMap->getTable($table)->getColumns();
         foreach (array_keys($columns) as $key) {
             if ($columns[$key]->isPrimaryKey()) {
                 $pk = $columns[$key];
                 break;
             }
         }
     }
     return $pk;
 }