public static function rechargerUserProjet($usersprojets, Doctrine_Connection $conn = null)
 {
     $conn->execute("TRUNCATE TABLE ei_project_user");
     //On vide la table pour purger les utilisateurs
     $userprojet = $usersprojets->getElementsByTagName("user_projet");
     if ($userprojet->length > 0) {
         //s'il ya au moins une balise trouvé
         $stmt = $conn->prepare("INSERT INTO ei_project_user (project_id, user_id, project_ref,user_ref,role) " . "VALUES (:project_id, :user_id, :project_ref,:user_ref,:role) " . "ON DUPLICATE KEY UPDATE project_id=project_id,user_id=user_id,project_ref=project_ref,user_ref=user_ref,role=:role");
         foreach ($userprojet as $u) {
             $project_id = $u->getAttribute("project_id");
             $user_id = $u->getAttribute("user_id");
             $project_ref = $u->getAttribute("project_ref");
             $user_ref = $u->getAttribute("user_ref");
             $role = $u->getElementsByTagName("role")->item(0)->nodeValue;
             //recherche du projet en base
             if ($project_id != null && $project_ref != null) {
                 $q = Doctrine_Core::getTable('EiProjet')->findOneByProjectIdAndRefId($project_id, $project_ref);
                 if ($q && $q != null) {
                     //si le projet existe
                     $stmt->bindValue("project_id", $project_id);
                     $stmt->bindValue("user_id", $user_id);
                     $stmt->bindValue("project_ref", $project_ref);
                     $stmt->bindValue("user_ref", $user_ref);
                     $stmt->bindValue("role", $role);
                     $stmt->execute(array());
                 }
             }
         }
     }
 }
 protected function getAdapter(Doctrine_Connection $connection)
 {
     $adapterName = strtolower($connection->getDriverName());
     if (!isset($this->adapters[$adapterName])) {
         throw new dmException(sprintf('%s is not supported. Available adapters are %s', $adapterName, implode(', ', array_keys($this->adapters))));
     }
     return new $this->adapters[$adapterName]($this->filesystem, $connection);
 }
 public function getAssignmentsHistory($subject_id = null, Doctrine_Connection $conn = null)
 {
     $q = "SELECT sa_vw.* FROM  ei_subject_assignment_vw as sa_vw   ";
     if ($subject_id != null) {
         $q .= "  WHERE  sah_subject_id=" . $subject_id;
     }
     $q .= ' Order by  sah_date DESC Limit 20';
     return $conn->fetchAll($q);
 }
 private function proceedStep1_6($exists = false)
 {
     if ($exists == true) {
         $reqSQL = "SELECT * FROM ei_node WHERE type='EiDataSet';";
         $results = $this->connexion->execute($reqSQL);
         $noeudsFils = $results->fetchAll();
         $requeteToUpdate = "UPDATE ei_data_set SET ei_node_id = #{EI_NODE_ID} WHERE id = #{ID};";
         $requeteGlobale = array();
         foreach ($noeudsFils as $noeud) {
             // Remplacement NODE ID.
             $tmpRequete = str_replace("#{EI_NODE_ID}", $noeud["id"], $requeteToUpdate);
             // Remplacement OBJ ID.
             $tmpRequete = str_replace("#{ID}", $noeud["obj_id"], $tmpRequete);
             // Ajout dans la requête globale.
             $requeteGlobale[] = $tmpRequete;
         }
         // Préparation de la requête.
         $this->displayResultStep("Préparation de la requête...");
         $requete = implode(" ", $requeteGlobale);
         // Exécution de la requête.
         $this->displayResultStep("Exécution de la requête...");
         if (strlen($requete) > 5) {
             $this->connexion->execute($requete);
         }
         // Fin.
         $this->displayResultStep("Processus terminé avec succès.");
     } else {
         $this->displayResultStep("Mise à jour du node_id du jeu de données omise.");
     }
     return false;
 }
Exemple #5
0
 /**
  * returns the maximum primary key value
  *
  * @return integer
  */
 public final function getMaxIdentifier()
 {
     $sql = "SELECT MAX(" . $this->getIdentifier() . ") FROM " . $this->getTableName();
     $stmt = $this->conn->getDBH()->query($sql);
     $data = $stmt->fetch(PDO::FETCH_NUM);
     return isset($data[0]) ? $data[0] : 1;
 }
Exemple #6
0
 public function __construct(Doctrine_Manager $manager, $adapter)
 {
     $this->supported = array('sequences' => true, 'indexes' => true, 'summary_functions' => true, 'order_by_text' => true, 'current_id' => true, 'affected_rows' => true, 'transactions' => true, 'savepoints' => true, 'limit_queries' => true, 'LOBs' => true, 'replace' => 'emulated', 'sub_selects' => true, 'auto_increment' => false, 'primary_key' => true, 'result_introspection' => true, 'prepared_statements' => true, 'identifier_quoting' => true, 'pattern_escaping' => true);
     $this->properties['sql_file_delimiter'] = "\n/\n";
     $this->properties['varchar2_max_length'] = 4000;
     $this->properties['number_max_precision'] = 38;
     parent::__construct($manager, $adapter);
 }
Exemple #7
0
 /**
  * Retrieves an enum index.
  * @see enumValue()
  *
  * @param string $fieldName
  * @param mixed $value          value of the enum considered
  * @return integer              can be string if native enums are used.
  */
 public function enumIndex($fieldName, $value)
 {
     $values = $this->getEnumValues($fieldName);
     if ($this->_conn->getAttribute(Doctrine_Core::ATTR_USE_NATIVE_ENUM)) {
         return $value;
     }
     return array_search($value, $values);
 }
Exemple #8
0
 /**
  * drops this view from the database
  *
  * @throws Doctrine_View_Exception
  * @return void
  */
 public function drop()
 {
     try {
         $this->_conn->execute(sprintf(self::DROP, $this->_name));
     } catch (Doctrine_Exception $e) {
         throw new Doctrine_View_Exception($e->__toString());
     }
 }
 /**
  * Execute the shutdown procedure.
  *
  * @return void
  */
 public function shutdown()
 {
     if ($this->connection !== null) {
         $this->connection = null;
     }
     if ($this->_doctrineConnection !== null) {
         $this->_doctrineConnection->getManager()->closeConnection($this->_doctrineConnection);
     }
 }
 /** Returns the name of the Doctrine database.
  *
  * @throws RuntimeException If the active connection has no DSN.
  * @return string
  */
 protected function getDatabaseName()
 {
     /* Why oh why does Doctrine_Connection not do this for us? */
     /** @noinspection PhpVoidFunctionResultUsedInspection */
     if (!($dsn = $this->_connection->getOption('dsn'))) {
         throw new RuntimeException(sprintf('Doctrine connection "%s" does not have a DSN!', $this->_connection->getName()));
     }
     $info = $this->_connection->getManager()->parsePdoDsn($dsn);
     return isset($info['dbname']) ? $info['dbname'] : null;
 }
Exemple #11
0
 /**
  * the constructor
  *
  * @param Doctrine_Manager $manager
  * @param PDO $pdo                          database handle
  */
 public function __construct(Doctrine_Manager $manager, $adapter)
 {
     $this->supported = array('sequences' => true, 'indexes' => true, 'affected_rows' => true, 'summary_functions' => true, 'order_by_text' => true, 'transactions' => true, 'savepoints' => true, 'current_id' => true, 'limit_queries' => 'emulated', 'LOBs' => true, 'replace' => 'emulated', 'sub_selects' => true, 'auto_increment' => true, 'primary_key' => true, 'result_introspection' => true, 'prepared_statements' => true, 'identifier_quoting' => false, 'pattern_escaping' => true);
     // initialize all driver options
     /**
     $this->options['DBA_username'] = false;
     $this->options['DBA_password'] = false;
     $this->options['database_path'] = '';
     $this->options['database_extension'] = '.gdb';
     $this->options['server_version'] = '';
     */
     parent::__construct($manager, $adapter);
 }
Exemple #12
0
 public function __construct(Doctrine_Manager $manager, $adapter)
 {
     $this->supported = array('sequences' => true, 'indexes' => true, 'summary_functions' => true, 'order_by_text' => true, 'current_id' => true, 'affected_rows' => true, 'transactions' => true, 'savepoints' => true, 'limit_queries' => true, 'LOBs' => true, 'replace' => 'emulated', 'sub_selects' => true, 'auto_increment' => false, 'primary_key' => true, 'result_introspection' => true, 'prepared_statements' => true, 'identifier_quoting' => true, 'pattern_escaping' => true);
     /**
     $this->options['DBA_username'] = false;
     $this->options['DBA_password'] = false;
     $this->options['database_name_prefix'] = false;
     $this->options['emulate_database'] = true;
     $this->options['default_tablespace'] = false;
     $this->options['default_text_field_length'] = 2000;
     $this->options['result_prefetching'] = false;
     */
     parent::__construct($manager, $adapter);
 }
Exemple #13
0
 /**
  * Executes a prepared statement
  *
  * If the prepared statement included parameter markers, you must either:
  * call PDOStatement->bindParam() to bind PHP variables to the parameter markers:
  * bound variables pass their value as input and receive the output value,
  * if any, of their associated parameter markers or pass an array of input-only
  * parameter values
  *
  *
  * @param array $params             An array of values with as many elements as there are
  *                                  bound parameters in the SQL statement being executed.
  * @return boolean                  Returns TRUE on success or FALSE on failure.
  */
 public function execute($params = null)
 {
     try {
         //$event = new Doctrine_Event($this, Doctrine_Event::STMT_EXECUTE, $this->getQuery(), $params);
         //$this->_conn->getListener()->preStmtExecute($event);
         $result = true;
         //if ( ! $event->skipOperation) {
         $result = $this->_stmt->execute($params);
         //$this->_conn->incrementQueryCount();
         //}
         //$this->_conn->getListener()->postStmtExecute($event);
         return $result;
     } catch (PDOException $e) {
         $this->_conn->rethrowException($e, $this);
     }
     return false;
 }
Exemple #14
0
 /**
  * fetchAll
  * Returns an array containing all of the result set rows
  *
  * @param integer $fetchMode            Controls how the next row will be returned to the caller.
  *                                      This value must be one of the Doctrine::FETCH_* constants,
  *                                      defaulting to Doctrine::FETCH_BOTH
  *
  * @param integer $columnIndex          Returns the indicated 0-indexed column when the value of $fetchStyle is
  *                                      Doctrine::FETCH_COLUMN. Defaults to 0.
  *
  * @return array
  */
 public function fetchAll($fetchMode = Doctrine::FETCH_BOTH, $columnIndex = null)
 {
     $event = new Doctrine_Event($this, Doctrine_Event::STMT_FETCHALL, $this->getQuery());
     $event->fetchMode = $fetchMode;
     $event->columnIndex = $columnIndex;
     $this->_conn->getListener()->preFetchAll($event);
     if (!$event->skipOperation) {
         if ($columnIndex !== null) {
             $data = $this->_stmt->fetchAll($fetchMode, $columnIndex);
         } else {
             $data = $this->_stmt->fetchAll($fetchMode);
         }
         $event->data = $data;
     }
     $this->_conn->getListener()->postFetchAll($event);
     return $data;
 }
 /**
  * Handles error as specified by {@link self::$_onErrorBehavior}
  * 
  * @param type $message The error message from the exception thrown.
  * 
  * @see self::handlePopulationError()
  * @return void
  */
 protected static function handleError($message)
 {
     switch (self::$_onErrorBehavior) {
         case 'continue':
             break;
         case 'stop':
             self::$conn->commit();
             throw new sfFileException($message);
             break;
         case 'rollback':
             self::$conn->rollback();
             throw new sfFileException($message);
             break;
         default:
             throw new Exception('La opcion: ' . self::$_onErrorBehavior . ' no es una opcion válida para la clave on_error_behavior');
             break;
     }
 }
Exemple #16
0
 /**
  * applyInheritance
  * applies column aggregation inheritance to DQL / SQL query
  *
  * @return string
  */
 public function applyInheritance()
 {
     // get the inheritance maps
     $array = array();
     foreach ($this->_aliasMap as $componentAlias => $data) {
         $tableAlias = $this->getTableAlias($componentAlias);
         $array[$tableAlias][] = $data['table']->inheritanceMap;
     }
     // apply inheritance maps
     $str = '';
     $c = array();
     $index = 0;
     foreach ($array as $tableAlias => $maps) {
         $a = array();
         // don't use table aliases if the query isn't a select query
         if ($this->type !== Doctrine_Query::SELECT) {
             $tableAlias = '';
         } else {
             $tableAlias .= '.';
         }
         foreach ($maps as $map) {
             $b = array();
             foreach ($map as $field => $value) {
                 $identifier = $this->_conn->quoteIdentifier($tableAlias . $field);
                 if ($index > 0) {
                     $b[] = '(' . $identifier . ' = ' . $value . ' OR ' . $identifier . ' IS NULL)';
                 } else {
                     $b[] = $identifier . ' = ' . $value;
                 }
             }
             if (!empty($b)) {
                 $a[] = implode(' AND ', $b);
             }
         }
         if (!empty($a)) {
             $c[] = implode(' AND ', $a);
         }
         $index++;
     }
     $str .= implode(' AND ', $c);
     return $str;
 }
 private function replaceTokens($query)
 {
     $tokens = $this->getQueryTokens($query);
     foreach ($tokens as $token) {
         switch (strtolower($token)) {
             case 'prefix':
                 $query = str_replace('${prefix}', $this->connection->getPrefix(), $query);
                 AppKitLogger::verbose("Replaced prefix %s", $query);
                 break;
             case 'username':
                 $query = str_replace('${username}', $this->user->user_name, $query);
                 break;
             case 'retained_flag':
                 $query = str_replace('${retained_flag}', $this->useRetained, $query);
                 break;
             case 'active_flag':
                 $query = str_replace('${active_flag}', 1, $query);
                 break;
             default:
                 $query = $this->resolveReferenceToken($token, $query);
         }
     }
     return $query;
 }
 public function deleteInactiveFunctions(EiProjet $ei_project, Doctrine_Connection $conn)
 {
     if ($ei_project == null) {
         return null;
     }
     //Suppression de l'objet EiFonction
     $conn->createQuery()->from('EiFonction f')->where('KalFunction.function_id=f.function_id And KalFunction.function_ref=f.function_ref')->andWhere('KalFunction.project_id=? And KalFunction.project_ref=? And KalFunction.is_active = false', array($ei_project->getProjectId(), $ei_project->getRefId()))->execute()->delete();
     //Suppression de la fonction sous Script
     $conn->createQuery()->delete()->from('KalFunction f')->where('f.project_id=? And f.project_ref=? And f.is_active = false', array($ei_project->getProjectId(), $ei_project->getRefId()))->execute();
 }
Exemple #19
0
 /**
  * Closes the specified connection
  *
  * @param Doctrine_Connection $connection
  * @return void
  */
 public function closeConnection(Doctrine_Connection $connection)
 {
     $connection->close();
     $key = array_search($connection, $this->_connections, true);
     if ($key !== false) {
         unset($this->_connections[$key]);
     }
     $this->_currIndex = key($this->_connections);
     unset($connection);
 }
Exemple #20
0
 /**
  * the constructor
  *
  * @param Doctrine_Manager $manager
  * @param PDO $pdo                          database handle
  */
 public function __construct(Doctrine_Manager $manager, $adapter)
 {
     // initialize all driver options
     $this->supported = array('sequences' => 'emulated', 'indexes' => true, 'affected_rows' => true, 'transactions' => true, 'summary_functions' => true, 'order_by_text' => true, 'current_id' => 'emulated', 'limit_queries' => 'emulated', 'LOBs' => true, 'replace' => 'emulated', 'sub_selects' => true, 'auto_increment' => true, 'primary_key' => true, 'result_introspection' => true, 'prepared_statements' => 'emulated');
     parent::__construct($manager, $adapter);
 }
 /**
  * @param Doctrine_Connection $conn
  */
 private function transformDataSetTreeFromRecursiveToNested(Doctrine_Connection $conn)
 {
     ini_set("memory_limit", "-1");
     /** @var EiDataSetTable $tableDs */
     $tableDs = Doctrine_Core::getTable("EiDataSet");
     // Requête permettant de supprimer les lignes de JDD orphelines.
     $sqlRemoveOrphans = "DELETE FROM ei_data_line WHERE ei_data_line_parent_id IS NULL AND ei_data_set_structure_id IS NULL;";
     // Requêtes permettant de récupérer les arbres des JDD à traiter.
     $sqlGetDS = "SELECT id FROM ei_data_set WHERE id IN (SELECT ei_data_set_id FROM ei_data_line WHERE lft IS NULL OR rgt IS NULL GROUP BY ei_data_set_id HAVING COUNT(ei_data_set_id) > 0);";
     // Update level from structure.
     $sqlUpdateLevel = "UPDATE ei_data_line dl, ei_data_set_structure dss SET dl.level = dss.level WHERE dl.ei_data_set_structure_id = dss.id";
     // Update root_id from root elements.
     $updateRootId = "UPDATE ei_data_line SET root_id = id WHERE root_id IS NULL AND level = 0;";
     try {
         $this->log("[INFO] ---   Début MAJ des arbres de JDD   ---");
         $this->log("[INFO] Suppression des orphelins.");
         $conn->execute($sqlRemoveOrphans);
         $this->log("[INFO] Récupération de la liste des jeux de données à mettre à jour.");
         $dataSets = $conn->execute($sqlGetDS)->fetchAll();
         $this->log("[INFO] " . count($dataSets) . " jeu(x) de données à mettre à jour.");
         if (count($dataSets) > 0) {
             foreach ($dataSets as $dataSet) {
                 /** @var EiDataSet $ds */
                 $ds = $tableDs->find($dataSet["id"]);
                 $ds->updateDataLines($ds->generateOldXML());
             }
         }
         $this->log("[INFO] Jeux de données mis à jour.");
         $conn->execute($sqlUpdateLevel);
         $this->log("[INFO] Mise à jour des niveaux de chaque ligne relativement à la structure.");
         $conn->execute($updateRootId);
         $this->log("[INFO] Mise à jour du root_id pour chaque élément root.");
         $this->log("[INFO] ---   Fin MAJ des arbres de JDD   ---");
     } catch (Exception $e) {
         $this->log("[ERROR] " . $e->getMessage());
     }
 }
 protected function canUpdateWithOrderBy(Doctrine_Connection $conn)
 {
     // If transaction level is greater than 1,
     // query will throw exceptions when using this function
     return $conn->getTransactionLevel() < 2 && $conn->getDriverName() != 'Pgsql' && $conn->getDriverName() != 'Sqlite' && $conn->getDriverName() != 'Mssql';
 }
 public function configureDoctrineConnectionDoctrine2(Doctrine_Connection $connection)
 {
     $connection->setAttribute(Doctrine_Core::ATTR_VALIDATE, false);
 }
Exemple #24
0
 /**
  * the constructor
  *
  * @param Doctrine_Manager $manager
  * @param PDO $pdo                          database handle
  */
 public function __construct(Doctrine_Manager $manager, $adapter)
 {
     parent::__construct($manager, $adapter);
 }
  public function delete(Doctrine_Connection $conn = null)
  {

    $id = $this->getId();

    $conn->beginTransaction();
      try
      {
        $return = parent::delete($conn); // try to delete first, delete index after
        $conn->commit();

    $index = dsPersonTable::getLuceneIndex();
    
    foreach ($index->find('pk:'.$id) as $hit)
    {
      $index->delete($hit->id);
    }

        return true;
      }
      catch (Exception $e)
      {
        $conn->rollBack();
        //throw $e;
        return false;
      }

  }
 /**
  * @access private
  * Formats the value in this Filter and adds quotes if necessary
  *
  * @author Jannis Moßhammer <*****@*****.**>
  **/
 private function formatValues(Doctrine_Connection $c)
 {
     $value = array();
     if (is_array($this->value)) {
         foreach ($this->value as $v) {
             if (!is_numeric($v)) {
                 $v = $c->quote($v, "string");
             }
             $value[] = $c->quote($v, "decimal");
         }
         return $value;
     } else {
         return $c->quote($this->value, "string");
     }
 }
 public function configureDoctrineConnection(Doctrine_Connection $conn)
 {
     $conn->setCollate('utf8_unicode_ci');
 }
Exemple #28
0
 public function __construct(Doctrine_Manager $manager, $adapter)
 {
     $this->supported = array('sequences' => true, 'indexes' => true, 'summary_functions' => true, 'order_by_text' => true, 'current_id' => true, 'affected_rows' => true, 'transactions' => true, 'savepoints' => true, 'limit_queries' => true, 'LOBs' => true, 'replace' => 'emulated', 'sub_selects' => true, 'auto_increment' => false, 'primary_key' => true, 'result_introspection' => true, 'prepared_statements' => true, 'identifier_quoting' => true, 'pattern_escaping' => true);
     parent::__construct($manager, $adapter);
 }
Exemple #29
0
 /**
  * Generates a string representation of a connection.
  *
  * This method returns an html dump of a connection, containing state, open
  * transactions and loaded tables.
  *
  * @param Doctrine_Connection $connection
  * @return string
  */
 public static function getConnectionAsString(Doctrine_Connection $connection)
 {
     $r[] = '<pre>';
     $r[] = 'Doctrine_Connection object';
     $r[] = 'State               : ' . Doctrine_Lib::getConnectionStateAsString($connection->transaction->getState());
     $r[] = 'Open Transactions   : ' . $connection->transaction->getTransactionLevel();
     $r[] = 'Table in memory     : ' . $connection->count();
     $r[] = 'Driver name         : ' . $connection->getAttribute(Doctrine::ATTR_DRIVER_NAME);
     $r[] = "</pre>";
     return implode("\n", $r) . "<br>";
 }
 protected function canUpdateWithOrderBy(Doctrine_Connection $conn)
 {
   // If transaction level is greater than 1,
   // query will throw exceptions when using this function
   return $conn->getTransactionLevel() < 2 &&
     // some drivers do not support UPDATE with ORDER BY query syntax
     $conn->getDriverName() != 'Pgsql' && $conn->getDriverName() != 'Sqlite';
 }