Example #1
0
File: Sort.php Project: acp3/core
 /**
  * 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;
 }
Example #2
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;
 }
Example #3
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.");
     }
 }
Example #4
0
 /**
  * @param string $moduleName
  *
  * @return boolean
  */
 public function moduleIsInstalled($moduleName)
 {
     return $this->db->fetchColumn("SELECT COUNT(*) FROM {$this->systemModuleRepository->getTableName()} WHERE `name` = ?", [$moduleName]) == 1;
 }
Example #5
0
 /**
  * @param int $entryId
  *
  * @return array
  */
 public function getOneById($entryId)
 {
     return $this->db->fetchAssoc("SELECT * FROM {$this->getTableName()} WHERE id = ?", [$entryId]);
 }
Example #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]);
 }