Skip to content
Extraits de code Groupes Projets
Valider 0b9a3990 rédigé par mattab's avatar mattab
Parcourir les fichiers

DbHelper class

parent a20afb2f
Branches
Étiquettes
Aucune requête de fusion associée trouvée
...@@ -40,17 +40,6 @@ class Common ...@@ -40,17 +40,6 @@ class Common
*/ */
const HTML_ENCODING_QUOTE_STYLE = ENT_QUOTES; const HTML_ENCODING_QUOTE_STYLE = ENT_QUOTES;
/**
*
* @param string
* @return string Line breaks and line carriage removed
*/
public static function sanitizeLineBreaks($value)
{
$value = str_replace(array("\n", "\r", "\0"), '', $value);
return $value;
}
/* /*
* Database * Database
*/ */
...@@ -343,6 +332,17 @@ class Common ...@@ -343,6 +332,17 @@ class Common
: $value; : $value;
} }
/**
*
* @param string
* @return string Line breaks and line carriage removed
*/
public static function sanitizeLineBreaks($value)
{
$value = str_replace(array("\n", "\r", "\0"), '', $value);
return $value;
}
/** /**
* Returns a sanitized variable value from the $_GET and $_POST superglobal. * Returns a sanitized variable value from the $_GET and $_POST superglobal.
* If the variable doesn't have a value or an empty value, returns the defaultValue if specified. * If the variable doesn't have a value or an empty value, returns the defaultValue if specified.
......
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
* @category Piwik
* @package PluginsFunctions
*/
namespace Piwik;
use Exception;
use Piwik\Db\Adapter;
use Piwik\Db\Schema;
class DbHelper
{
/**
* Get list of tables installed
*
* @param bool $forceReload Invalidate cache
* @return array Tables installed
*/
public static function getTablesInstalled($forceReload = true)
{
return Schema::getInstance()->getTablesInstalled($forceReload);
}
/**
* Drop specific tables
*
* @param array $doNotDelete Names of tables to not delete
*/
public static function dropTables($doNotDelete = array())
{
Schema::getInstance()->dropTables($doNotDelete);
}
/**
* Returns true if Piwik is installed
*
* @since 0.6.3
*
* @return bool True if installed; false otherwise
*/
public static function isInstalled()
{
try {
return Schema::getInstance()->hasTables();
} catch (Exception $e) {
return false;
}
}
/**
* Truncate all tables
*/
public static function truncateAllTables()
{
Schema::getInstance()->truncateAllTables();
}
/**
* Creates an entry in the User table for the "anonymous" user.
*/
public static function createAnonymousUser()
{
Schema::getInstance()->createAnonymousUser();
}
/**
* Create all tables
*/
public static function createTables()
{
Schema::getInstance()->createTables();
}
/**
* Drop database, used in tests
*/
public static function dropDatabase()
{
if(defined('PIWIK_TEST_MODE') && PIWIK_TEST_MODE) {
Schema::getInstance()->dropDatabase();
}
}
/**
* Check database connection character set is utf8.
*
* @return bool True if it is (or doesn't matter); false otherwise
*/
public static function isDatabaseConnectionUTF8()
{
return \Zend_Registry::get('db')->isConnectionUTF8();
}
/**
* Checks the database server version against the required minimum
* version.
*
* @see config/global.ini.php
* @since 0.4.4
* @throws Exception if server version is less than the required version
*/
public static function checkDatabaseVersion()
{
\Zend_Registry::get('db')->checkServerVersion();
}
/**
* Disconnect from database
*/
public static function disconnectDatabase()
{
\Zend_Registry::get('db')->closeConnection();
}
/**
* Create database object and connect to database
* @param array|null $dbInfos
*/
public static function createDatabaseObject($dbInfos = null)
{
$config = Config::getInstance();
if (is_null($dbInfos)) {
$dbInfos = $config->database;
}
Piwik_PostEvent('Reporting.getDatabaseConfig', array(&$dbInfos));
$dbInfos['profiler'] = $config->Debug['enable_sql_profiler'];
$db = null;
Piwik_PostEvent('Reporting.createDatabase', array(&$db));
if (is_null($db)) {
$adapter = $dbInfos['adapter'];
$db = @Adapter::factory($adapter, $dbInfos);
}
\Zend_Registry::set('db', $db);
}
/**
* Create database
*
* @param string|null $dbName
*/
public static function createDatabase($dbName = null)
{
Schema::getInstance()->createDatabase($dbName);
}
/**
* Get the SQL to create Piwik tables
*
* @return array array of strings containing SQL
*/
public static function getTablesCreateSql()
{
return Schema::getInstance()->getTablesCreateSql();
}
/**
* Get the SQL to create a specific Piwik table
*
* @param string $tableName
* @return string SQL
*/
public static function getTableCreateSql($tableName)
{
return Schema::getInstance()->getTableCreateSql($tableName);
}
}
\ No newline at end of file
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter