Exemple #1
0
 /**
  * Moves a database result one step upwards/downwards
  *
  * @param string $action
  * @param string $table
  * @param string $idField
  * @param string $sortField
  * @param string $id
  * @param string $where
  *
  * @return boolean
  */
 private function moveOneStep($action, $table, $idField, $sortField, $id, $where = '')
 {
     $this->db->getConnection()->beginTransaction();
     try {
         $id = (int) $id;
         $table = $this->db->getPrefix() . $table;
         // Zusätzliche WHERE-Bedingung
         $where = !empty($where) ? 'a.' . $where . ' = b.' . $where . ' AND ' : '';
         // Aktuelles Element und das vorherige Element selektieren
         $queryString = 'SELECT a.%2$s AS other_id, a.%3$s AS other_sort, b.%3$s AS elem_sort FROM %1$s AS a, %1$s AS b WHERE %5$sb.%2$s = %4$s AND a.%3$s %6$s b.%3$s ORDER BY a.%3$s %7$s LIMIT 1';
         if ($action === 'up') {
             $query = $this->db->getConnection()->fetchAssoc(sprintf($queryString, $table, $idField, $sortField, $id, $where, '<', 'DESC'));
         } else {
             $query = $this->db->getConnection()->fetchAssoc(sprintf($queryString, $table, $idField, $sortField, $id, $where, '>', 'ASC'));
         }
         if (!empty($query)) {
             // Sortierreihenfolge des aktuellen Elementes zunächst auf 0 setzen
             // um Probleme mit möglichen Duplicate-Keys zu umgehen
             $this->db->getConnection()->update($table, [$sortField => 0], [$idField => $id]);
             $this->db->getConnection()->update($table, [$sortField => $query['elem_sort']], [$idField => $query['other_id']]);
             // Element nun den richtigen Wert zuweisen
             $this->db->getConnection()->update($table, [$sortField => $query['other_sort']], [$idField => $id]);
             $this->db->getConnection()->commit();
             return true;
         }
     } catch (\Exception $e) {
         $this->db->getConnection()->rollBack();
     }
     return false;
 }
Exemple #2
0
 /**
  * Executes all given SQL queries
  *
  * @param array $queries
  * @param string $moduleName
  *
  * @return bool
  * @throws \Doctrine\DBAL\ConnectionException
  */
 public function executeSqlQueries(array $queries, $moduleName = '')
 {
     if (count($queries) > 0) {
         $search = ['{pre}', '{engine}', '{charset}'];
         $replace = [$this->db->getPrefix(), 'ENGINE=InnoDB', 'CHARACTER SET `utf8` COLLATE `utf8_general_ci`'];
         $this->db->getConnection()->beginTransaction();
         try {
             foreach ($queries as $query) {
                 if (is_object($query) && $query instanceof \Closure) {
                     if ($query() === false) {
                         return false;
                     }
                 } elseif (!empty($query)) {
                     if (strpos($query, '{moduleId}') !== false) {
                         $query = str_replace('{moduleId}', $this->getModuleId($moduleName), $query);
                     }
                     $this->db->getConnection()->query(str_ireplace($search, $replace, $query));
                 }
             }
             $this->db->getConnection()->commit();
         } catch (\Exception $e) {
             $this->db->getConnection()->rollBack();
             $this->container->get('core.logger')->warning('installer', $e);
             return false;
         }
     }
     return true;
 }
Exemple #3
0
 /**
  * @inheritdoc
  */
 public function destroy($sessionId)
 {
     $this->secureSession();
     if ($this->request->getCookies()->has(self::SESSION_NAME)) {
         $cookie = new Cookie(self::SESSION_NAME, '', (new \DateTime())->modify('-3600 seconds'), $this->appPath->getWebRoot(), null, $this->request->getSymfonyRequest()->isSecure());
         $this->response->headers->setCookie($cookie);
     }
     // Delete the session from the database
     $this->db->getConnection()->delete($this->db->getPrefix() . 'sessions', ['session_id' => $sessionId]);
     return true;
 }