示例#1
0
 /**
  * @param string $date Date string.
  * @return int
  * @throws \PandaBase\Exception\ConnectionNotExistsException
  * @throws \PandaBase\Exception\RecordValueNotExists
  * @throws \PandaBase\Exception\TableDescriptorNotExists
  */
 protected function getHistoryAtDateInternal($date)
 {
     $tableDescriptor = $this->getTableDescriptor();
     $sql = "SELECT " . $tableDescriptor->get(TABLE_ID) . " FROM " . $tableDescriptor->get(TABLE_NAME) . " \n            WHERE " . $tableDescriptor->get(TABLE_ID) . "=:" . $tableDescriptor->get(TABLE_ID) . " AND :history_date >= history_from AND :history_date <= history_to";
     $result = ConnectionManager::getInstance()->getDefault()->fetchAssoc($sql, [$tableDescriptor->get(TABLE_ID) => $this->get($tableDescriptor->get(TABLE_ID)), "history_date" => $date]);
     return intval($result[$tableDescriptor->get(TABLE_ID)]);
 }
示例#2
0
 /**
  * @param $key
  * @param $value
  * @return mixed
  * @throws AccessDeniedException
  */
 public function set($key, $value)
 {
     // Ha van beállítva jogosultság, akkor ellenőrizni kell
     if (in_array(AccessibleObject::class, class_uses($this))) {
         /** @var AccessibleObject $object */
         $object = $this;
         if (!ConnectionManager::getInstance()->getAccessManager()->checkWriteAccess($object)) {
             throw new AccessDeniedException();
         }
     }
     $this->values[$key] = $value;
 }
示例#3
0
 /**
  * Registers services on the given container.
  *
  * This method should only be used to configure services and parameters.
  * It should not get services.
  *
  * @param Container $pimple A container instance
  */
 public function register(Container $pimple)
 {
     $configuration = $this->databaseConfig;
     ConnectionManager::getInstance()->initializeConnection($configuration);
     if (strtolower($configuration["charset"]) === "utf8") {
         ConnectionManager::getInstance()->getConnection($configuration["name"])->setNamesUTF8();
     }
     /*
      * A ConnectionManager önmagában is globálisan tudja tárolni a saját állapotát, ezért inkább factory-val kell
      * használni, nehogy a pimple-be beragadjon hibásan valami.
      */
     $pimple['db'] = $pimple->factory(function ($c) {
         return ConnectionManager::getInstance();
     });
 }
示例#4
0
 /**
  * @param $key
  * @return mixed
  * @throws AccessDeniedException
  */
 public function get($key)
 {
     if (!isset($this->values[$key])) {
         //throw new RecordValueNotExists("Value ".$key." not exists in ".$this->getTableDescriptor()->get(TableDescriptor::TABLE_NAME));
         return null;
     }
     // Ha van beállítva jogosultság, akkor ellenőrizni kell
     if (in_array(AccessibleObject::class, class_uses($this))) {
         /** @var AccessibleObject $object */
         $object = $this;
         if (!ConnectionManager::getInstance()->getAccessManager()->checkReadAccess($object)) {
             throw new AccessDeniedException();
         }
     }
     return $this->values[$key];
 }
 public function testPersistNew()
 {
     $newRecord = new TestRecord(CREATE_INSTANCE, ["table_col_1" => "add_record", "store_date" => date('Y-m-d H:i:s')]);
     $actualConnection = \PandaBase\Connection\ConnectionManager::getInstance()->getDefault();
     $this->connectionManager->persist($newRecord);
     $this->assertNotEquals(null, $newRecord[$newRecord->getTableDescriptor()->get(TABLE_ID)]);
 }
<?php

use PandaBase\Connection\ConnectionManager;
// Get the manager instance
$connectionManager = ConnectionManager::getInstance();
// Add a connection to manager object
$connectionManager->initializeConnection(["name" => "test_connection", "driver" => "mysql", "dbname" => "test_dbname", "host" => "127.0.0.1", "user" => "root", "password" => ""]);
// Add more connection to manager object
$connectionManager->initializeConnection([["name" => "test_connection1", "driver" => "mysql", "dbname" => "test_dbname1", "host" => "127.0.0.1", "user" => "root", "password" => ""], ["name" => "test_connection2", "driver" => "mysql", "dbname" => "test_dbname2", "host" => "127.0.0.1", "user" => "root", "password" => ""]]);
示例#7
0
 /**
  * Release all connection.
  *
  */
 public function releaseConnections()
 {
     foreach ($this->getAllConnection() as $connection) {
         $connection->release();
     }
     ConnectionManager::getInstance()->connectionInstances = [];
     ConnectionManager::getInstance()->defaultConnectionName = "";
 }
示例#8
0
 /**
  * @param $className
  * @return \PandaBase\Record\InstanceRecordContainer
  */
 public function getInstances($className)
 {
     $this->buildSqlString();
     return ConnectionManager::getInstance()->getInstanceRecords($className, $this->sql, $this->searchParameters);
 }
 public function remove()
 {
     $sql = "DELETE FROM" . " " . $this->databaseRecord->getTableDescriptor()->get(TableDescriptor::TABLE_NAME) . "\n                WHERE " . $this->databaseRecord->getTableDescriptor()->get(TableDescriptor::TABLE_ID) . "= :" . $this->databaseRecord->getTableDescriptor()->get(TableDescriptor::TABLE_ID);
     $prepared_statement = ConnectionManager::getInstance()->getConnection()->prepare($sql);
     $prepared_statement->bindValue($this->databaseRecord->getTableDescriptor()->get(TableDescriptor::TABLE_ID), $this->databaseRecord->get($this->databaseRecord->getTableDescriptor()->get(TableDescriptor::TABLE_ID)));
     $prepared_statement->execute();
 }
 /**
  * @return void
  * @throws DatabaseManagerNotExists
  * @throws TableDescriptorNotExists
  * @throws RecordValueNotExists
  */
 public function remove()
 {
     $remove_query = "UPDATE " . $this->tableDescriptor->get(TableDescriptor::TABLE_NAME) . " SET record_status = 0, history_to = NOW() WHERE " . $this->tableDescriptor->get(TableDescriptor::TABLE_ID) . "=:" . $this->tableDescriptor->get(TableDescriptor::TABLE_ID) . " AND record_status=1";
     $prepared_statement = ConnectionManager::getInstance()->getConnection()->prepare($remove_query);
     $prepared_statement->bindValue($this->tableDescriptor->get(TableDescriptor::TABLE_ID), $this->databaseRecord->get($this->tableDescriptor->get(TableDescriptor::TABLE_ID)));
     $prepared_statement->execute();
 }
示例#11
0
 /**
  * @param TableDescriptor $tableDescriptor
  * @throws DatabaseManagerNotExists
  */
 function __construct(TableDescriptor $tableDescriptor)
 {
     $this->connectionManager = ConnectionManager::getInstance();
     $this->tableDescriptor = $tableDescriptor;
     $this->databaseRecord = null;
 }
示例#12
0
 public static function garbageCollect($max_life_sec)
 {
     $max_life_min = round($max_life_sec / 60);
     $statement = ConnectionManager::getInstance()->getDefault()->prepare("\n          DELETE from " . self::$sessionName . " WHERE updated<date_sub(NOW(), interval :max_life_min minute)\n        ");
     $statement->bindValue("max_life_min", $max_life_min);
     $statement->execute();
     return true;
 }
示例#13
0
 protected function setUp()
 {
     \PandaBase\Connection\ConnectionManager::getInstance()->initializeConnection(["name" => "database_connection", "driver" => "mysql", "dbname" => "kodiapp", "host" => "localhost", "user" => "root", "password" => "", "charset" => "utf8"]);
     Session::initSession(["name" => "session", "lifetime" => 7200]);
     $this->sessionStorage = new \KodiApp\Session\SessionStorage();
 }
示例#14
0
 /**
  * @return bool
  */
 public function checkPermissions($uri)
 {
     foreach ($this->permissions as $permissionPath => $permissionRoles) {
         if ($permissionPath[0] !== "/") {
             $permissionPath = "/" . $permissionPath;
         }
         if (substr($permissionPath, -1) !== "/") {
             $permissionPath = $permissionPath . "/";
         }
         $match = preg_match($permissionPath, $uri);
         if ($match == 1) {
             if (in_array(Role::ROLE_ANONYMOUS, $permissionRoles)) {
                 $user = $this->getUser();
                 if ($user != null) {
                     ConnectionManager::getInstance()->registerAccessUser($this->getUser());
                 }
                 return true;
             }
             $user = $this->getUser();
             if ($user == null) {
                 return false;
             }
             foreach ($permissionRoles as $permissionRole) {
                 if (in_array($permissionRole, $user->getRoles())) {
                     $user = $this->getUser();
                     if ($user != null) {
                         ConnectionManager::getInstance()->registerAccessUser($this->getUser());
                     }
                     return true;
                 }
             }
             return false;
         }
     }
     return true;
 }