Beispiel #1
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;
 }
Beispiel #2
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;
 }
Beispiel #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;
 }
Beispiel #4
0
 /**
  * @param array $formData
  * @throws \Exception
  */
 public function createSuperUser(array $formData)
 {
     /** @var \ACP3\Core\Database\Connection db */
     $this->db = $this->container->get('core.db');
     $salt = $this->secure->salt(UserModel::SALT_LENGTH);
     $currentDate = gmdate('Y-m-d H:i:s');
     $queries = ["INSERT INTO\n                `{pre}users`\n            VALUES\n                (1, 1, {$this->db->getConnection()->quote($formData["user_name"])}, '{$this->secure->generateSaltedPassword($salt, $formData["user_pwd"], 'sha512')}', '{$salt}', '', 0, '', '1', '', 0, '{$formData["mail"]}', 0, '', '', '', '', '', '', '', '', 0, 0, {$this->db->getConnection()->quote($formData["date_format_long"])}, {$this->db->getConnection()->quote($formData["date_format_short"])}, '{$formData["date_time_zone"]}', '{$this->translator->getLocale()}', '{$currentDate}');", "INSERT INTO `{pre}acl_user_roles` (`user_id`, `role_id`) VALUES (1, 4);"];
     if ($this->container->get('core.modules.schemaHelper')->executeSqlQueries($queries) === false) {
         throw new \Exception("Error while creating the super user.");
     }
 }
Beispiel #5
0
 /**
  * Executes the SQL update statement
  *
  * @param array $data
  * @param int|array $entryId
  * @return bool|int
  */
 public function update(array $data, $entryId)
 {
     return $this->db->executeTransactionalQuery(function () use($data, $entryId) {
         return $this->db->getConnection()->update($this->getTableName(), $data, $this->getIdentifier($entryId));
     });
 }
Beispiel #6
0
 /**
  * @param int $diff
  * @param int $leftId
  *
  * @throws \Doctrine\DBAL\DBALException
  */
 protected function adjustFollowingNodesAfterInsert($diff, $leftId)
 {
     $this->db->getConnection()->executeUpdate("UPDATE {$this->nestedSetRepository->getTableName()} SET left_id = left_id + ?, right_id = right_id + ? WHERE left_id >= ?", [$diff, $diff, $leftId]);
 }