コード例 #1
0
ファイル: jdb.pgsql.html_cli.php プロジェクト: hadrienl/jelix
 function getTests()
 {
     try {
         $prof = jProfiles::get('jdb', $this->dbProfile, true);
     } catch (Exception $e) {
         $this->sendMessage('UTjDbPgsql cannot be run: ' . $e->getMessage());
         return array();
     }
     return parent::getTests();
 }
コード例 #2
0
ファイル: jDb_profilesTest.php プロジェクト: hadrienl/jelix
 function testCommonValues()
 {
     $profile = array('trace' => 1, 'connection_timeout' => 10, 'exceptions' => 1);
     jProfiles::createVirtualProfile('acme', '__common__', $profile);
     $profile = array('wsdl' => "http://example.com/wsdl1", 'connection_timeout' => 25);
     jProfiles::createVirtualProfile('acme', 'foo', $profile);
     $p = jProfiles::get('acme', 'foo');
     $expected = array('trace' => 1, 'exceptions' => 1, 'connection_timeout' => 25, 'wsdl' => "http://example.com/wsdl1", '_name' => 'foo');
     $this->assertEquals($expected, $p);
 }
コード例 #3
0
 protected function loadProfile()
 {
     try {
         jProfiles::get('jcache', 'jforms', true);
     } catch (Exception $e) {
         // no profile, let's create a default profile
         $cacheDir = jApp::tempPath('jforms');
         jFile::createDir($cacheDir);
         $params = array('enabled' => 1, 'driver' => 'file', 'ttl' => 3600 * 48, 'automatic_cleaning_factor' => 3, 'cache_dir' => $cacheDir, 'directory_level' => 3);
         jProfiles::createVirtualProfile('jcache', 'jforms', $params);
     }
 }
コード例 #4
0
ファイル: jSelectorDao.class.php プロジェクト: mdouchin/jelix
 function __construct($sel, $profile)
 {
     $p = jProfiles::get('jdb', $profile);
     if ($p['driver'] == 'pdo') {
         $this->driver = substr($p['dsn'], 0, strpos($p['dsn'], ':'));
     } else {
         $this->driver = $p['driver'];
     }
     $this->dbType = $p['dbtype'];
     $this->_compiler = 'jDaoCompiler';
     $this->_compilerPath = JELIX_LIB_PATH . 'dao/jDaoCompiler.class.php';
     parent::__construct($sel);
 }
コード例 #5
0
 /**
  *
  */
 function search()
 {
     $localConfig = jApp::configPath('localconfig.ini.php');
     $ini = new jIniFileModifier($localConfig);
     $jdbParams = array("driver" => $ini->getValue('db_driver', 'localiz_plugin') ?: 'pgsql', "host" => $ini->getValue('db_host', 'localiz_plugin'), "port" => $ini->getValue('db_port', 'localiz_plugin') ?: 5432, "database" => $ini->getValue('db_database', 'localiz_plugin'), "user" => $ini->getValue('db_user', 'localiz_plugin') ?: 'postgres', "password" => $ini->getValue('db_password', 'localiz_plugin'));
     jProfiles::createVirtualProfile('jdb', 'localiz_plugin', $jdbParams);
     $cnx = jDb::getConnection('localiz_plugin');
     $sql = sprintf($ini->getValue('db_query', 'localiz_plugin'), $this->param('term'));
     $res = $cnx->query($sql);
     $rep = $this->getResponse('json');
     $rep->data = array();
     foreach ($res as $record) {
         $rep->data[] = array('oid' => $record->oid, 'typcode' => $record->typcode, 'value' => $record->value, 'label' => $record->label, 'longlabel' => $record->longlabel, 'geometrytype' => $record->geometrytype, 'xmin' => $record->xmin, 'ymin' => $record->ymin, 'xmax' => $record->xmax, 'ymax' => $record->ymax);
     }
     return $rep;
 }
コード例 #6
0
ファイル: soapclientTest.php プロジェクト: hadrienl/jelix
 function testCall()
 {
     try {
         $profile = jProfiles::get("jsoapclient");
         if (!isset($profile['wsdl']) || $profile['wsdl'] == '') {
             $this->markTestSkipped('no wsdl specified in profile for jSoapClient. cannot test jSoapClient::get()');
             return;
         }
     } catch (Exception $e) {
         $this->markTestSkipped('no profile for jSoapClient. cannot test jSoapClient::get()');
         return;
     }
     $client = jSoapClient::get();
     $result = $client->hello('Sylvain');
     $this->assertEquals("Hello Sylvain", $result);
     $result = $client->__soapCall('hello', array('Sylvain'));
     $this->assertEquals("Hello Sylvain", $result);
 }
コード例 #7
0
 public function getDatasourceConnection()
 {
     $dtParams = $this->getDatasourceParameters();
     $jdbParams = array();
     if ($this->provider == 'spatialite') {
         $repository = $this->project->getRepository();
         $jdbParams = array("driver" => 'sqlite3', "database" => realpath($repository->getPath() . $dtParams->dbname), "extensions" => "libspatialite.so");
     } else {
         if ($this->provider == 'postgres') {
             $jdbParams = array("driver" => 'pgsql', "host" => $dtParams->host, "port" => (int) $dtParams->port, "database" => $dtParams->dbname, "user" => $dtParams->user, "password" => $dtParams->password);
         } else {
             return null;
         }
     }
     $profile = $this->id;
     jProfiles::createVirtualProfile('jdb', $profile, $jdbParams);
     return jDb::getConnection($profile);
 }
コード例 #8
0
    function testTools()
    {
        try {
            $profile = jProfiles::get('jdb', 'testapp_sqlite', true);
        } catch (Exception $e) {
            $this->sendMessage("UTjDbSqlite cannot be run : no sqlite profile");
            return;
        }
        $tools = jDb::getConnection('testapp_sqlite')->tools();
        $fields = $tools->getFieldList('products');
        $structure = '<array>
    <object key="id" class="jDbFieldProperties">
        <string property="type" value="integer" />
        <string property="name" value="id" />
        <boolean property="notNull" value="true" />
        <boolean property="primary" value="true" />
        <boolean property="autoIncrement" value="true" />
        <boolean property="hasDefault" value="false" />
        <string property="default" value="" />
        <integer property="length" value="0" />
    </object>
    <object key="name" class="jDbFieldProperties">
        <string property="type" value="varchar" />
        <string property="name" value="name" />
        <boolean property="notNull" value="true" />
        <boolean property="primary" value="false" />
        <boolean property="autoIncrement" value="false" />
        <boolean property="hasDefault" value="false" />
        <string property="default" value="" />
        <integer property="length" value="150" />
    </object>
    <object key="price" class="jDbFieldProperties">
        <string property="type" value="float" />
        <string property="name" value="price" />
        <boolean property="notNull" value="false" />
        <boolean property="primary" value="false" />
        <boolean property="autoIncrement" value="false" />
        <boolean property="hasDefault" value="true" />
        <string property="default" value="0" />
        <integer property="length" value="0" />
    </object>
</array>';
        $this->assertComplexIdenticalStr($fields, $structure, 'bad results');
    }
コード例 #9
0
ファイル: install.php プロジェクト: hadrienl/jelix
 function install()
 {
     if (!$this->firstDbExec()) {
         return;
     }
     $this->execSQLScript('install');
     //Create tables if they do not exist yet because of a specific configuration
     //(which is the case of testapp's out of the box config)
     $this->execSQLScript('sql/install_jsession.schema', 'jelix');
     $this->execSQLScript('sql/install_jcache.schema', 'jelix');
     try {
         $dbprofile = jProfiles::get('jdb', 'testapp_pgsql', true);
         $this->useDbProfile('testapp_pgsql');
     } catch (Exception $e) {
         // no profile for pgsql, don't install tables in pgsql
         return;
     }
     $this->execSQLScript('install');
     $this->execSQLScript('sql/install_jsession.schema', 'jelix');
 }
コード例 #10
0
 public function hasFtsSearches()
 {
     // Virtual jdb profile corresponding to the layer database
     $project = $this->key;
     $repository = $this->repository->getKey();
     $repositoryPath = realpath($this->repository->getPath());
     $repositoryPath = str_replace('\\', '/', $repositoryPath);
     $searchDatabase = $repositoryPath . '/default.qfts';
     if (!file_exists($searchDatabase)) {
         // Search for project database
         $searchDatabase = $repositoryPath . '/' . $project . '.qfts';
     }
     if (!file_exists($searchDatabase)) {
         return false;
     }
     $jdbParams = array("driver" => "pdo", "dsn" => 'sqlite:' . $searchDatabase);
     // Create the virtual jdb profile
     $searchJdbName = "jdb_" . $repository . '_' . $project;
     jProfiles::createVirtualProfile('jdb', $searchJdbName, $jdbParams);
     // Check FTS db ( tables and geometry storage
     try {
         $cnx = jDb::getConnection($searchJdbName);
         // Get metadata
         $sql = "\n            SELECT search_id, search_name, layer_name, geometry_storage, srid\n            FROM quickfinder_toc\n            WHERE geometry_storage != 'wkb'\n            ORDER BY priority\n            ";
         $res = $cnx->query($sql);
         $searches = array();
         foreach ($res as $item) {
             $searches[$item->search_id] = array('search_name' => $item->search_name, 'layer_name' => $item->layer_name, 'srid' => $item->srid);
         }
         if (count($searches) == 0) {
             return false;
         }
         return array('jdb_profile' => $searchJdbName, 'searches' => $searches);
     } catch (Exception $e) {
         return false;
     }
     return false;
 }
コード例 #11
0
ファイル: jDb.class.php プロジェクト: rodacom/jelix
 /**
  * return a database connector. It uses a temporay pool of connection to reuse
  * currently opened connections.
  *
  * @param string  $name  profile name to use. if empty, use the default one
  * @return jDbConnection  the connector
  */
 public static function getConnection($name = '')
 {
     return jProfiles::getOrStoreInPool('jdb', $name, array('jDb', '_createConnector'));
 }
コード例 #12
0
ファイル: jCache.class.php プロジェクト: havefnubb/havefnubb
 protected static function _getDriver($profile)
 {
     return jProfiles::getOrStoreInPool('jcache', $profile, array('jCache', '_loadDriver'), true);
 }
コード例 #13
0
 /**
  * declare a new db profile. if the content of the section is not given,
  * it will declare an alias to the default profile
  * @param string $name  the name of the new section/alias
  * @param null|string|array  $sectionContent the content of the new section, or null
  *     to create an alias.
  * @param boolean $force true:erase the existing profile
  * @return boolean true if the ini file has been changed
  */
 protected function declareDbProfile($name, $sectionContent = null, $force = true)
 {
     $profiles = new jIniFileModifier(jApp::configPath('profiles.ini.php'));
     if ($sectionContent == null) {
         if (!$profiles->isSection('jdb:' . $name)) {
             // no section
             if ($profiles->getValue($name, 'jdb') && !$force) {
                 // already a name
                 return false;
             }
         } else {
             if ($force) {
                 // existing section, and no content provided : we erase the section
                 // and add an alias
                 $profiles->removeValue('', 'jdb:' . $name);
             } else {
                 return false;
             }
         }
         $default = $profiles->getValue('default', 'jdb');
         if ($default) {
             $profiles->setValue($name, $default, 'jdb');
         } else {
             // default is a section
             $profiles->setValue($name, 'default', 'jdb');
         }
     } else {
         if ($profiles->getValue($name, 'jdb') !== null) {
             if (!$force) {
                 return false;
             }
             $profiles->removeValue($name, 'jdb');
         }
         if (is_array($sectionContent)) {
             foreach ($sectionContent as $k => $v) {
                 $profiles->setValue($k, $v, 'jdb:' . $name);
             }
         } else {
             $profile = $profiles->getValue($sectionContent, 'jdb');
             if ($profile !== null) {
                 $profiles->setValue($name, $profile, 'jdb');
             } else {
                 $profiles->setValue($name, $sectionContent, 'jdb');
             }
         }
     }
     $profiles->save();
     jProfiles::clear();
     return true;
 }
コード例 #14
0
 /**
  * Get field data from a database layer corresponding to a QGIS layer
  * @param string $datasource String corresponding to the QGIS <datasource> item for the layer
  * @return object containing the sql fields information
  */
 private function getDataFields($datasource)
 {
     // Get datasource information from QGIS
     $datasourceMatch = preg_match("#(?:dbname='([^ ]+)' )?(?:service='([^ ]+)' )?(?:host=([^ ]+) )?(?:port=([0-9]+) )?(?:user='******' )?(?:password='******' )?(?:sslmode=([^ ]+) )?(?:key='([^ ]+)' )?(?:estimatedmetadata=([^ ]+) )?(?:srid=([0-9]+) )?(?:type=([a-zA-Z]+) )?(?:table=\"([^ ]+)\" )?(?:\\()?(?:([^ ]+)\\) )?(?:sql=(.*))?#", $datasource, $dt);
     $dbname = $dt[1];
     $service = $dt[2];
     $host = $dt[3];
     $port = $dt[4];
     $user = $dt[5];
     $password = $dt[6];
     $sslmode = $dt[7];
     $key = $dt[8];
     $estimatedmetadata = $dt[9];
     $srid = $dt[10];
     $type = $dt[11];
     $table = $dt[12];
     $geocol = $dt[13];
     $sql = $dt[14];
     // If table contains schema name, like "public"."mytable"
     // We need to add double quotes around and find the real table name (without schema)
     // to retrieve the columns with jelix tools.
     $tableAlone = $table;
     $schema = '';
     if (preg_match('#"."#', $table)) {
         $table = '"' . $table . '"';
         $exp = explode('.', str_replace('"', '', $table));
         $tableAlone = $exp[1];
         $schema = $exp[0];
     }
     $this->schema = $schema;
     // Set some private properties
     $this->table = $table;
     $this->tableName = $tableAlone;
     $this->whereClause = $sql;
     $driver = $this->providerDriverMap[$this->provider];
     // Build array of parameters for the virtual profile
     if ($driver == 'sqlite3') {
         $jdbParams = array("driver" => $driver, "database" => realpath($this->repository->getPath() . $dbname), "extensions" => "libspatialite.so,mod_spatialite.so");
     } else {
         if (!empty($service)) {
             $jdbParams = array("driver" => $driver, "service" => $service);
         } else {
             $jdbParams = array("driver" => $driver, "host" => $host, "port" => (int) $port, "database" => $dbname, "user" => $user, "password" => $password);
         }
     }
     // Create the virtual jdb profile
     $profile = $this->layerId;
     jProfiles::createVirtualProfile('jdb', $profile, $jdbParams);
     // Get the fields using jelix tools for this connection
     $cnx = jDb::getConnection($profile);
     $tools = $cnx->tools();
     $sequence = null;
     $fields = $tools->getFieldList($tableAlone, $sequence);
     $this->dataFields = $fields;
     foreach ($this->dataFields as $fieldName => $prop) {
         // Detect primary key column
         if ($prop->primary && !in_array($fieldName, $this->primaryKeys)) {
             $this->primaryKeys[] = $fieldName;
         }
         // Detect geometry column
         if (in_array(strtolower($prop->type), $this->geometryDatatypeMap)) {
             $this->geometryColumn = $fieldName;
             $this->geometryType = strtolower($prop->type);
             // If postgresql, get real geometryType from geometry_columns (jelix prop gives 'geometry')
             if ($this->provider == 'postgres' and $this->geometryType == 'geometry') {
                 $cnx = jDb::getConnection($this->layerId);
                 $res = $cnx->query('SELECT type FROM geometry_columns WHERE f_table_name = ' . $cnx->quote($this->tableName));
                 $res = $res->fetch();
                 if ($res) {
                     $this->geometryType = strtolower($res->type);
                 }
             }
         }
     }
     // For views : add key from datasource
     if (!$this->primaryKeys and $key) {
         // check if layer is a view
         $cnx = jDb::getConnection($this->layerId);
         if ($this->provider == 'postgres') {
             $sql = " SELECT table_name FROM INFORMATION_SCHEMA.views";
             $sql .= " WHERE 2>1";
             $sql .= " AND (table_schema = ANY (current_schemas(false)) OR table_schema = " . $cnx->quote($schema) . ")";
             $sql .= " AND table_name=" . $cnx->quote($tableAlone);
         }
         if ($this->provider == 'spatialite') {
             $sql = " SELECT name FROM sqlite_master WHERE type = 'view'";
             $sql .= " AND name=" . $cnx->quote($tableAlone);
         }
         $res = $cnx->query($sql);
         if ($res->rowCount() > 0) {
             $this->primaryKeys[] = $key;
         }
     }
     return true;
 }
コード例 #15
0
 /**
  * clear the loaded profiles to force to reload the profiles file.
  * WARNING: it destroy all objects stored in the pool!
  */
 public static function clear()
 {
     self::$_profiles = null;
     self::$_objectPool = array();
     if (gc_enabled()) {
         gc_collect_cycles();
     }
 }
コード例 #16
0
 protected static function declareRedisProfile($ser, $cacheName, $repository, $project = null, $layers = null, $crs = null)
 {
     $cacheRedisHost = 'localhost';
     $cacheRedisPort = '6379';
     $cacheExpiration = (int) $ser->cacheExpiration;
     if (property_exists($ser, 'cacheRedisHost')) {
         $cacheRedisHost = trim($ser->cacheRedisHost);
     }
     if (property_exists($ser, 'cacheRedisPort')) {
         $cacheRedisPort = trim($ser->cacheRedisPort);
     }
     // Virtual cache profile parameter
     $cacheParams = array("driver" => "redis", "host" => $cacheRedisHost, "port" => $cacheRedisPort, "ttl" => $cacheExpiration);
     if ($project) {
         if ($layers) {
             $cacheParams["key_prefix"] = $repository . '/' . $project . '/' . $layers . '/' . $crs . '/';
         } else {
             $cacheParams["key_prefix"] = $repository . '/' . $project . '/';
         }
     } else {
         $cacheParams["key_prefix"] = $repository . '/';
     }
     if (property_exists($ser, 'cacheRedisDb') and !empty($ser->cacheRedisDb)) {
         $cacheParams['db'] = $ser->cacheRedisDb;
     }
     if (property_exists($ser, 'cacheRedisKeyPrefix') and !empty($ser->cacheRedisKeyPrefix)) {
         $cacheParams['key_prefix'] = $ser->cacheRedisKeyPrefix . $cacheParams['key_prefix'];
     }
     if (property_exists($ser, 'cacheRedisKeyPrefixFlushMethod') and !empty($ser->cacheRedisKeyPrefixFlushMethod)) {
         $cacheParams['key_prefix_flush_method'] = $ser->cacheRedisKeyPrefixFlushMethod;
     }
     // Create the virtual cache profile
     jProfiles::createVirtualProfile('jcache', $cacheName, $cacheParams);
 }
コード例 #17
0
 public static function clear()
 {
     self::$_profiles = null;
     self::$_objectPool = array();
 }
コード例 #18
0
 public static function createVirtualProfile($repository, $project, $layers, $crs)
 {
     // Set cache configuration
     $cacheName = 'lizmapCache_' . $repository . '_' . $project . '_' . $layers . '_' . $crs;
     // Storage type
     $ser = lizmap::getServices();
     $cacheStorageType = $ser->cacheStorageType;
     // Expiration time : take default one
     $cacheExpiration = (int) $ser->cacheExpiration;
     // Cache root directory
     $cacheRootDirectory = $ser->cacheRootDirectory;
     if (!is_writable($cacheRootDirectory) or !is_dir($cacheRootDirectory)) {
         $cacheRootDirectory = sys_get_temp_dir();
     }
     if ($cacheStorageType == 'file') {
         // CACHE CONTENT INTO FILE SYSTEM
         // Directory where to store the cached files
         $cacheDirectory = $cacheRootDirectory . '/' . $repository . '/' . $project . '/' . $layers . '/' . $crs . '/';
         // Create directory if needed
         if (!file_exists($cacheDirectory)) {
             mkdir($cacheDirectory, 0750, true);
         }
         // Virtual cache profile parameter
         $cacheParams = array("driver" => "file", "cache_dir" => $cacheDirectory, "file_locking" => True, "directory_level" => "5", "directory_umask" => "0750", "file_name_prefix" => "lizmap_", "cache_file_umask" => "0650", "ttl" => $cacheExpiration);
         // Create the virtual cache profile
         jProfiles::createVirtualProfile('jcache', $cacheName, $cacheParams);
     } else {
         // CACHE CONTENT INTO SQLITE DATABASE
         // Directory where to store the sqlite database
         $cacheDirectory = $cacheRootDirectory . '/' . $repository . '/' . $project . '/';
         if (!file_exists($cacheDirectory)) {
             mkdir($cacheDirectory, 0750, true);
         }
         // Create directory if needed
         $cacheDatabase = $cacheDirectory . $layers . '_' . $crs . '.db';
         $cachePdoDsn = 'sqlite:' . $cacheDatabase;
         // Create database and populate with table if needed
         if (!file_exists($cacheDatabase)) {
             copy(jApp::varPath() . "cacheTemplate.db", $cacheDatabase);
         }
         // Virtual jdb profile corresponding to the layer database
         $jdbParams = array("driver" => "pdo", "dsn" => $cachePdoDsn, "user" => "cache", "password" => "cache");
         // Create the virtual jdb profile
         $cacheJdbName = "jdb_" . $cacheName;
         jProfiles::createVirtualProfile('jdb', $cacheJdbName, $jdbParams);
         // Virtual cache profile parameter
         $cacheParams = array("driver" => "db", "dbprofile" => $cacheJdbName, "ttl" => $cacheExpiration);
         // Create the virtual cache profile
         jProfiles::createVirtualProfile('jcache', $cacheName, $cacheParams);
     }
 }
コード例 #19
0
ファイル: jDb.class.php プロジェクト: havefnubb/havefnubb
 public static function clearProfiles()
 {
     jProfiles::clear();
 }
コード例 #20
0
 /**
  * @param string $profile  the profile name
  */
 public static function get($profile = '')
 {
     return jProfiles::getOrStoreInPool('jsoapclient', $profile, array('jSoapClient', '_getClient'));
 }
コード例 #21
0
ファイル: jKVDb.class.php プロジェクト: havefnubb/havefnubb
 public static function getProfile($name = null)
 {
     return jProfiles::get('jkvdb', $name);
 }