aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornikrou <nikrou@piwigo.org>2010-01-28 11:30:36 +0000
committernikrou <nikrou@piwigo.org>2010-01-28 11:30:36 +0000
commit386864cd2612ac743e182253541bddfebed80606 (patch)
treef2c8a0d0f72bb919e28f751c8fc20544a919ba8e
parent22191d91a223c4e71399f32ff42cf61a53e9d19d (diff)
Feature 511 : add support for sqlite database engine
Using session_write_close function when session handler use database because write is called after object destruction. git-svn-id: http://piwigo.org/svn/trunk@4781 68402e56-0260-453c-a942-63ccdbb3a9ee
-rw-r--r--include/calendar_base.class.php16
-rw-r--r--include/calendar_monthly.class.php8
-rw-r--r--include/dblayer/dblayers.inc.php4
-rw-r--r--include/dblayer/functions_mysql.inc.php5
-rw-r--r--include/dblayer/functions_pgsql.inc.php66
-rw-r--r--include/dblayer/functions_sqlite.inc.php566
-rw-r--r--include/functions_calendar.inc.php20
-rw-r--r--include/functions_session.inc.php1
-rw-r--r--include/ws_functions.inc.php2
-rw-r--r--install/piwigo_structure-sqlite.sql532
10 files changed, 1151 insertions, 69 deletions
diff --git a/include/calendar_base.class.php b/include/calendar_base.class.php
index 41a15d918..4424c62f9 100644
--- a/include/calendar_base.class.php
+++ b/include/calendar_base.class.php
@@ -271,24 +271,20 @@ $this->get_date_where($level).'
if ( empty($page['chronology_date']) )
return;
- $sub_query = '';
+ $sub_queries = array();
$nb_elements = count($page['chronology_date']);
for ($i=0; $i<$nb_elements; $i++)
{
if ( 'any' === $page['chronology_date'][$i] )
{
- $sub_query .= '\'any\'';
+ $sub_queries[] = '\'any\'';
}
else
{
- $sub_query .= pwg_db_cast_to_text($this->calendar_levels[$i]['sql']);
- }
- if ($i<($nb_elements-1))
- {
- $sub_query .= ',';
+ $sub_queries[] = pwg_db_cast_to_text($this->calendar_levels[$i]['sql']);
}
}
- $query = 'SELECT '.pwg_db_concat_ws($sub_query, '-').' AS period';
+ $query = 'SELECT '.pwg_db_concat_ws($sub_queries, '-').' AS period';
$query .= $this->inner_sql .'
AND ' . $this->date_field . ' IS NOT NULL
GROUP BY period';
@@ -296,12 +292,12 @@ GROUP BY period';
$current = implode('-', $page['chronology_date'] );
$upper_items = array_from_query( $query, 'period');
- usort($upper_items, 'version_compare');
+ usort($upper_items, 'date_compare');
$upper_items_rank = array_flip($upper_items);
if ( !isset($upper_items_rank[$current]) )
{
array_push($upper_items, $current);// just in case (external link)
- usort($upper_items, 'version_compare');
+ usort($upper_items, 'date_compare');
$upper_items_rank = array_flip($upper_items);
}
$current_rank = $upper_items_rank[$current];
diff --git a/include/calendar_monthly.class.php b/include/calendar_monthly.class.php
index eb28735e7..21aefd2ad 100644
--- a/include/calendar_monthly.class.php
+++ b/include/calendar_monthly.class.php
@@ -147,12 +147,12 @@ function get_date_where($max_levels=3)
$e = $date[CYEAR] . '-';
if (isset($date[CMONTH]) and $date[CMONTH]!=='any')
{
- $b .= $date[CMONTH] . '-';
- $e .= $date[CMONTH] . '-';
+ $b .= sprintf('%02d-', $date[CMONTH]);
+ $e .= sprintf('%02d-', $date[CMONTH]);
if (isset($date[CDAY]) and $date[CDAY]!=='any')
{
- $b .= $date[CDAY];
- $e .= $date[CDAY];
+ $b .= sprintf('%02d', $date[CDAY]);
+ $e .= sprintf('%02d', $date[CDAY]);
}
else
{
diff --git a/include/dblayer/dblayers.inc.php b/include/dblayer/dblayers.inc.php
index 235b02cf9..73c972832 100644
--- a/include/dblayer/dblayers.inc.php
+++ b/include/dblayer/dblayers.inc.php
@@ -29,4 +29,8 @@ $dblayers['mysql'] = array('engine' => 'MySQL',
$dblayers['pgsql'] = array('engine' => 'PostgreSQL',
'function_available' => 'pg_connect'
);
+
+$dblayers['sqlite'] = array('engine' => 'SQLite',
+ 'function_available' => 'sqlite_open'
+ );
?> \ No newline at end of file
diff --git a/include/dblayer/functions_mysql.inc.php b/include/dblayer/functions_mysql.inc.php
index cc5ca3081..80c172a36 100644
--- a/include/dblayer/functions_mysql.inc.php
+++ b/include/dblayer/functions_mysql.inc.php
@@ -458,9 +458,10 @@ function do_maintenance_all_tables()
}
}
-function pwg_db_concat_ws($string, $separaor)
+function pwg_db_concat_ws($array, $separator)
{
- return 'CONCAT_WS(\''.$separaor.'\','. $string.')';
+ $string = implode($array, ',');
+ return 'CONCAT_WS(\''.$separator.'\','. $string.')';
}
function pwg_db_cast_to_text($string)
diff --git a/include/dblayer/functions_pgsql.inc.php b/include/dblayer/functions_pgsql.inc.php
index 9e51aef04..afbb635cd 100644
--- a/include/dblayer/functions_pgsql.inc.php
+++ b/include/dblayer/functions_pgsql.inc.php
@@ -70,8 +70,6 @@ function pwg_query($query)
{
global $conf,$page,$debug,$t2;
- // Log::getInstance()->debug($query);
-
$start = get_moment();
($result = pg_query($query)) or die($query."\n<br>".pg_last_error());
@@ -212,9 +210,9 @@ function mass_updates($tablename, $dbfields, $datas, $flags=0)
{
if (count($datas) == 0)
return;
- // depending on the MySQL version, we use the multi table update or N update queries
+
if (count($datas) < 10)
- { // MySQL is prior to version 4.0.4, multi table update feature is not available
+ {
foreach ($datas as $data)
{
$query = '
@@ -378,61 +376,26 @@ function do_maintenance_all_tables()
$all_tables = array();
// List all tables
- $query = 'SHOW TABLES LIKE \''.$prefixeTable.'%\'';
- $result = pwg_query($query);
- while ($row = pwg_db_fetch_assoc($result))
- {
- array_push($all_tables, $row[0]);
- }
-
- // Repair all tables
- $query = 'REPAIR TABLE '.implode(', ', $all_tables);
- $mysql_rc = pwg_query($query);
-
- // Re-Order all tables
- foreach ($all_tables as $table_name)
- {
- $all_primary_key = array();
-
- $query = 'DESC '.$table_name.';';
- $result = pwg_query($query);
- while ($row = pwg_db_fetch_assoc($result))
- {
- if ($row['Key'] == 'PRI')
- {
- array_push($all_primary_key, $row['Field']);
- }
- }
+ $query = 'SELECT tablename FROM pg_tables
+WHERE tablename like \''.$prefixeTable.'%\'';
- if (count($all_primary_key) != 0)
- {
- $query = 'ALTER TABLE '.$table_name.' ORDER BY '.implode(', ', $all_primary_key).';';
- $mysql_rc = $mysql_rc && pwg_query($query);
- }
- }
+ $all_tables = array_from_query($query, 'tablename');
// Optimize all tables
- $query = 'OPTIMIZE TABLE '.implode(', ', $all_tables);
- $mysql_rc = $mysql_rc && pwg_query($query);
- if ($mysql_rc)
+ foreach ($all_tables as $table)
{
- array_push(
- $page['infos'],
- l10n('Optimizations completed')
- );
- }
- else
- {
- array_push(
- $page['errors'],
- l10n('Optimizations errors')
- );
+ $query = 'VACUUM FULL '.$table;
+ pwg_query($query);
}
+ array_push($page['infos'],
+ l10n('Optimizations completed')
+ );
}
-function pwg_db_concat_ws($string, $separaor)
+function pwg_db_concat_ws($array, $separator)
{
- return 'ARRAY_TO_STRING(ARRAY['.$string.'],\''.$separaor.'\')';
+ $string = implode($array, ',');
+ return 'ARRAY_TO_STRING(ARRAY['.$string.'],\''.$separator.'\')';
}
function pwg_db_cast_to_text($string)
@@ -449,7 +412,6 @@ function pwg_db_cast_to_text($string)
function get_enums($table, $field)
{
$typname = preg_replace('/'.$GLOBALS['prefixeTable'].'/', '', $table);
- Log::getInstance()->debug($typname);
$typname .= '_' . $field;
$query = 'SELECT
diff --git a/include/dblayer/functions_sqlite.inc.php b/include/dblayer/functions_sqlite.inc.php
new file mode 100644
index 000000000..ede8b7521
--- /dev/null
+++ b/include/dblayer/functions_sqlite.inc.php
@@ -0,0 +1,566 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based picture gallery |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2009 Piwigo Team http://piwigo.org |
+// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
+// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify |
+// | it under the terms of the GNU General Public License as published by |
+// | the Free Software Foundation |
+// | |
+// | This program is distributed in the hope that it will be useful, but |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
+// | General Public License for more details. |
+// | |
+// | You should have received a copy of the GNU General Public License |
+// | along with this program; if not, write to the Free Software |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA. |
+// +-----------------------------------------------------------------------+
+
+define('REQUIRED_SQLITE_VERSION', '3.0.0');
+define('DB_ENGINE', 'SQLite');
+
+define('DB_REGEX_OPERATOR', 'REGEXP');
+define('DB_RANDOM_FUNCTION', 'RANDOM');
+
+/**
+ *
+ * simple functions
+ *
+ */
+
+function pwg_db_connect($host, $user, $password, $database)
+{
+ global $conf;
+
+ $db_file = sprintf('%s/%s.db', $conf['local_data_dir'], $database);
+
+ $link = new SQLite3($db_file);
+ $link->createFunction('now', 'pwg_now', 0);
+ $link->createFunction('md5', 'md5', 1);
+
+ $link->createAggregate('std', 'pwg_std_step', 'pwg_std_finalize');
+ $link->createFunction('regexp', 'pwg_regexp', 2);
+
+ return $link;
+}
+
+function pwg_db_check_charset()
+{
+ return true;
+}
+
+function pwg_get_db_version()
+{
+ global $pwg_db_link;
+
+ $versionInfos = $pwg_db_link->version();
+ return $versionInfos['versionString'];
+}
+
+function pwg_query($query)
+{
+ global $conf,$page,$debug,$t2,$pwg_db_link;
+
+ $start = get_moment();
+
+ $truncate_pattern = '`truncate(.*)`i';
+ $insert_pattern = '`(INSERT INTO [^)]*\)\s*VALUES)(\([^)]*\))\s*,\s*(.*)`mi';
+
+ if (preg_match($truncate_pattern, $query, $matches))
+ {
+ $query = str_replace('TRUNCATE TABLE', 'DELETE FROM', $query);
+ $truncate_query = true;
+ ($result = $pwg_db_link->exec($query)) or die($query."\n<br>".$pwg_db_link->lastErrorMsg());
+ }
+ elseif (preg_match($insert_pattern, $query, $matches))
+ {
+ $base_query = substr($query, 0, strlen($matches[1])+1);
+ $values_pattern = '`\)\s*,\s*\(`';
+ $values = preg_split($values_pattern, substr($query, strlen($matches[1])+1));
+ $values[0] = substr($values[0], 1);
+ $values[count($values)-1] = substr($values[count($values)-1],
+ 0,
+ strlen($values[count($values)-1])-1
+ );
+ for ($n=0;$n<count($values);$n++)
+ {
+ $query = $base_query . '('. $values[$n] . ")\n;";
+ ($result = $pwg_db_link->query($query))
+ or die($query."\n<br>".$pwg_db_link->lastErrorMsg());
+ }
+ }
+ else
+ {
+ ($result = $pwg_db_link->query($query))
+ or die($query."\n<br>".$pwg_db_link->lastErrorMsg());
+ }
+
+ $time = get_moment() - $start;
+
+ if (!isset($page['count_queries']))
+ {
+ $page['count_queries'] = 0;
+ $page['queries_time'] = 0;
+ }
+
+ $page['count_queries']++;
+ $page['queries_time']+= $time;
+
+ if ($conf['show_queries'])
+ {
+ $output = '';
+ $output.= '<pre>['.$page['count_queries'].'] ';
+ $output.= "\n".$query;
+ $output.= "\n".'(this query time : ';
+ $output.= '<b>'.number_format($time, 3, '.', ' ').' s)</b>';
+ $output.= "\n".'(total SQL time : ';
+ $output.= number_format($page['queries_time'], 3, '.', ' ').' s)';
+ $output.= "\n".'(total time : ';
+ $output.= number_format( ($time+$start-$t2), 3, '.', ' ').' s)';
+ if ( $result!=null and preg_match('/\s*SELECT\s+/i',$query) )
+ {
+ $output.= "\n".'(num rows : ';
+ $output.= pwg_db_num_rows($result).' )';
+ }
+ elseif ( $result!=null
+ and preg_match('/\s*INSERT|UPDATE|REPLACE|DELETE\s+/i',$query)
+ and !isset($truncate_query))
+ {
+ $output.= "\n".'(affected rows : ';
+ $output.= pwg_db_changes($result).' )';
+ }
+ $output.= "</pre>\n";
+
+ $debug .= $output;
+ }
+
+ return $result;
+}
+
+function pwg_db_nextval($column, $table)
+{
+ $query = '
+SELECT MAX('.$column.')+1
+ FROM '.$table;
+ list($next) = pwg_db_fetch_row(pwg_query($query));
+ if (is_null($next))
+ {
+ $next = 1;
+ }
+ return $next;
+}
+
+/**
+ *
+ * complex functions
+ *
+ */
+
+function pwg_db_changes(SQLite3Result $result=null)
+{
+ global $pwg_db_link;
+
+ return $pwg_db_link->changes();
+}
+
+function pwg_db_num_rows($result)
+{
+ return $result->numColumns();
+}
+
+function pwg_db_fetch_assoc($result)
+{
+ return $result->fetchArray(SQLITE3_ASSOC);
+}
+
+function pwg_db_fetch_row($result)
+{
+ return $result->fetchArray(SQLITE3_NUM);
+}
+
+function pwg_db_fetch_object($result)
+{
+ return $result;
+}
+
+function pwg_db_free_result($result)
+{
+}
+
+function pwg_db_real_escape_string($s)
+{
+ global $pwg_db_link;
+
+ return $pwg_db_link->escapeString($s);
+}
+
+function pwg_db_insert_id()
+{
+ global $pwg_db_link;
+
+ return $pwg_db_link->lastInsertRowID();
+}
+
+/**
+ *
+ * complex functions
+ *
+ */
+
+/**
+ * creates an array based on a query, this function is a very common pattern
+ * used here
+ *
+ * @param string $query
+ * @param string $fieldname
+ * @return array
+ */
+function array_from_query($query, $fieldname)
+{
+ $array = array();
+
+ $result = pwg_query($query);
+ while ($row = pwg_db_fetch_assoc($result))
+ {
+ array_push($array, $row[$fieldname]);
+ }
+
+ return $array;
+}
+
+define('MASS_UPDATES_SKIP_EMPTY', 1);
+/**
+ * updates multiple lines in a table
+ *
+ * @param string table_name
+ * @param array dbfields
+ * @param array datas
+ * @param int flags - if MASS_UPDATES_SKIP_EMPTY - empty values do not overwrite existing ones
+ * @return void
+ */
+function mass_updates($tablename, $dbfields, $datas, $flags=0)
+{
+ if (count($datas) == 0)
+ return;
+
+ foreach ($datas as $data)
+ {
+ $query = '
+UPDATE '.$tablename.'
+ SET ';
+ $is_first = true;
+ foreach ($dbfields['update'] as $key)
+ {
+ $separator = $is_first ? '' : ",\n ";
+
+ if (isset($data[$key]) and $data[$key] != '')
+ {
+ $query.= $separator.$key.' = \''.$data[$key].'\'';
+ }
+ else
+ {
+ if ($flags & MASS_UPDATES_SKIP_EMPTY )
+ continue; // next field
+ $query.= "$separator$key = NULL";
+ }
+ $is_first = false;
+ }
+ if (!$is_first)
+ {// only if one field at least updated
+ $query.= '
+ WHERE ';
+ $is_first = true;
+ foreach ($dbfields['primary'] as $key)
+ {
+ if (!$is_first)
+ {
+ $query.= ' AND ';
+ }
+ if ( isset($data[$key]) )
+ {
+ $query.= $key.' = \''.$data[$key].'\'';
+ }
+ else
+ {
+ $query.= $key.' IS NULL';
+ }
+ $is_first = false;
+ }
+ pwg_query($query);
+ }
+ }
+}
+
+
+/**
+ * inserts multiple lines in a table
+ *
+ * @param string table_name
+ * @param array dbfields
+ * @param array inserts
+ * @return void
+ */
+
+function mass_inserts($table_name, $dbfields, $datas)
+{
+ if (count($datas) != 0)
+ {
+ $first = true;
+
+ $packet_size = 16777216;
+ $packet_size = $packet_size - 2000; // The last list of values MUST not exceed 2000 character*/
+ $query = '';
+
+ foreach ($datas as $insert)
+ {
+ if (strlen($query) >= $packet_size)
+ {
+ pwg_query($query);
+ $first = true;
+ }
+
+ if ($first)
+ {
+ $query = '
+INSERT INTO '.$table_name.'
+ ('.implode(',', $dbfields).')
+ VALUES';
+ $first = false;
+ }
+ else
+ {
+ $query .= '
+ , ';
+ }
+
+ $query .= '(';
+ foreach ($dbfields as $field_id => $dbfield)
+ {
+ if ($field_id > 0)
+ {
+ $query .= ',';
+ }
+
+ if (!isset($insert[$dbfield]) or $insert[$dbfield] === '')
+ {
+ $query .= 'NULL';
+ }
+ else
+ {
+ $query .= "'".$insert[$dbfield]."'";
+ }
+ }
+ $query .= ')';
+ }
+ pwg_query($query);
+ }
+}
+
+/**
+ * Do maintenance on all PWG tables
+ *
+ * @return none
+ */
+function do_maintenance_all_tables()
+{
+ global $prefixeTable, $page;
+
+ $all_tables = array();
+
+ // List all tables
+ $query = 'SELECT name FROM SQLITE_MASTER
+WHERE name LIKE \''.$prefixeTable.'%\'';
+
+ $all_tables = array_from_query($query, 'name');
+ foreach ($all_tables as $table_name)
+ {
+ $query = 'VACUUM '.$table_name.';';
+ $result = pwg_query($query);
+ }
+
+ array_push($page['infos'],
+ l10n('Optimizations completed')
+ );
+}
+
+function pwg_db_concat_ws($array, $separator)
+{
+ $glue = sprintf(' || \'%s\' || ', $separator);
+
+ return implode($array, $glue);
+}
+
+function pwg_db_cast_to_text($string)
+{
+ return $string;
+}
+
+/**
+ * returns an array containing the possible values of an enum field
+ *
+ * @param string tablename
+ * @param string fieldname
+ */
+function get_enums($table, $field)
+{
+ return array();
+}
+
+// get_boolean transforms a string to a boolean value. If the string is
+// "false" (case insensitive), then the boolean value false is returned. In
+// any other case, true is returned.
+function get_boolean( $string )
+{
+ $boolean = true;
+ if ('f' == $string || 'false' == $string)
+ {
+ $boolean = false;
+ }
+ return $boolean;
+}
+
+/**
+ * returns boolean string 'true' or 'false' if the given var is boolean
+ *
+ * @param mixed $var
+ * @return mixed
+ */
+function boolean_to_string($var)
+{
+ if (!empty($var) && ($var == 't'))
+ {
+ return 'true';
+ }
+ else
+ {
+ return 'false';
+ }
+}
+
+/**
+ *
+ * interval and date functions
+ *
+ */
+
+function pwg_db_get_recent_period_expression($period, $date='CURRENT_DATE')
+{
+ if ($date!='CURRENT_DATE')
+ {
+ $date = '\''.$date.'\'';
+ }
+
+ return 'date('.$date.',\''.$period.' DAY\')';
+}
+
+function pwg_db_get_recent_period($period, $date='CURRENT_DATE')
+{
+ $query = 'select '.pwg_db_get_recent_period_expression($period, $date);
+ list($d) = pwg_db_fetch_row(pwg_query($query));
+
+ return $d;
+}
+
+function pwg_db_get_date_YYYYMM($date)
+{
+ return 'strftime(\'%Y%m\','.$date.')';
+}
+
+function pwg_db_get_date_MMDD($date)
+{
+ return 'strftime(\'%m%d\','.$date.')';
+}
+
+function pwg_db_get_year($date)
+{
+ return 'strftime(\'%Y\','.$date.')';
+}
+
+function pwg_db_get_month($date)
+{
+ return 'strftime(\'%m\','.$date.')';
+}
+
+function pwg_db_get_week($date, $mode=null)
+{
+ return 'strftime(\'%W\','.$date.')';
+}
+
+function pwg_db_get_dayofmonth($date)
+{
+ return 'strftime(\'%d\','.$date.')';
+}
+
+function pwg_db_get_dayofweek($date)
+{
+ return 'strftime(\'%w\','.$date.')+1';
+}
+
+function pwg_db_get_weekday($date)
+{
+ return 'strftime(\'%w\','.$date.')';
+}
+
+// my_error returns (or send to standard output) the message concerning the
+// error occured for the last mysql query.
+function my_error($header, $die)
+{
+ global $pwg_db_link;
+
+ $error = '[sqlite error]'.$pwg_db_link->lastErrorMsg()."\n";
+ $error .= $header;
+
+ if ($die)
+ {
+ fatal_error($error);
+ }
+ echo("<pre>");
+ trigger_error($error, E_USER_WARNING);
+ echo("</pre>");
+}
+
+// sqlite create functions
+function pwg_now()
+{
+ return date('Y-m-d H:i:s');
+}
+
+function pwg_regexp($pattern, $string)
+{
+ $pattern = sprintf('`%s`', $pattern);
+ return preg_match($pattern, $string);
+}
+
+function pwg_std_step(&$values, $rownumber, $value)
+{
+ $values[] = $value;
+
+ return $values;
+}
+
+function pwg_std_finalize(&$values, $rownumber)
+{
+ if (count($values)<=1)
+ {
+ return 0;
+ }
+
+ $total = 0;
+ $total_square = 0;
+ foreach ($values as $value)
+ {
+ $total += $value;
+ $total_square += pow($value, 2);
+ }
+
+ $mean = $total/count($values);
+ $var = $total_square/count($values) - pow($mean, 2);
+
+ return sqrt($var);
+}
+?>
diff --git a/include/functions_calendar.inc.php b/include/functions_calendar.inc.php
index 9191bb157..73df86fbb 100644
--- a/include/functions_calendar.inc.php
+++ b/include/functions_calendar.inc.php
@@ -289,4 +289,24 @@ WHERE id IN (' . implode(',',$page['items']) .')';
}
pwg_debug('end initialize_calendar');
}
+
+/*
+ * callback to sort array with date comparaison
+ *
+ **/
+function date_compare(&$a, &$b)
+{
+ $parts = explode('-', $a);
+ foreach ($parts as &$p) {
+ $p = (int)$p;
+ }
+ $a = implode('-', $parts);
+ $parts = explode('-', $b);
+ foreach ($parts as &$p) {
+ $p = (int)$p;
+ }
+ $b = implode('-', $parts);
+
+ return strcmp($a, $b);
+}
?> \ No newline at end of file
diff --git a/include/functions_session.inc.php b/include/functions_session.inc.php
index 79fe21c4d..fe5fd01c0 100644
--- a/include/functions_session.inc.php
+++ b/include/functions_session.inc.php
@@ -70,6 +70,7 @@ if (isset($conf['session_save_handler'])
}
session_name($conf['session_name']);
session_set_cookie_params(0, cookie_path());
+ register_shutdown_function('session_write_close');
}
/**
diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php
index 439516b7e..66cd950ef 100644
--- a/include/ws_functions.inc.php
+++ b/include/ws_functions.inc.php
@@ -875,7 +875,7 @@ UPDATE '.IMAGES_TABLE.'
SET level='.(int)$params['level'].'
WHERE id IN ('.implode(',',$params['image_id']).')';
$result = pwg_query($query);
- $affected_rows = pwg_db_affected_rows();
+ $affected_rows = pwg_db_changes();
if ($affected_rows)
{
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
diff --git a/install/piwigo_structure-sqlite.sql b/install/piwigo_structure-sqlite.sql
new file mode 100644
index 000000000..8528ef01b
--- /dev/null
+++ b/install/piwigo_structure-sqlite.sql
@@ -0,0 +1,532 @@
+-----------------------------------------------------------------------------
+-- piwigo_caddie
+-----------------------------------------------------------------------------
+
+DROP TABLE IF EXISTS piwigo_caddie;
+CREATE TABLE "piwigo_caddie"
+(
+ "user_id" INTEGER default 0 NOT NULL,
+ "element_id" INTEGER default 0 NOT NULL,
+ PRIMARY KEY ("user_id","element_id")
+);
+
+-----------------------------------------------------------------------------
+-- piwigo_categories
+-----------------------------------------------------------------------------
+
+DROP TABLE IF EXISTS piwigo_categories;
+CREATE TABLE "piwigo_categories"
+(
+ "id" INTEGER NOT NULL,
+ "name" VARCHAR(255) default '' NOT NULL,
+ "id_uppercat" INTEGER,
+ "comment" TEXT,
+ "dir" VARCHAR(255),
+ "rank" INTEGER,
+ "status" VARCHAR(50) default 'public',
+ "site_id" INTEGER default 1,
+ "visible" BOOLEAN default true,
+ "uploadable" BOOLEAN default false,
+ "representative_picture_id" INTEGER,
+ "uppercats" TEXT,
+ "commentable" BOOLEAN default true,
+ "global_rank" VARCHAR(255),
+ "image_order" VARCHAR(128),
+ "permalink" VARCHAR(64),
+ PRIMARY KEY ("id"),
+ CONSTRAINT "categories_i3" UNIQUE ("permalink")
+);
+
+CREATE INDEX "categories_i2" ON "piwigo_categories" ("id_uppercat");
+
+-----------------------------------------------------------------------------
+-- piwigo_config
+-----------------------------------------------------------------------------
+
+DROP TABLE IF EXISTS piwigo_config;
+CREATE TABLE piwigo_config
+(
+ "param" VARCHAR(40) default '' NOT NULL,
+ "value" TEXT,
+ "comment" VARCHAR(255),
+ PRIMARY KEY ("param")
+);
+
+-----------------------------------------------------------------------------
+-- piwigo_favorites
+-----------------------------------------------------------------------------
+
+DROP TABLE IF EXISTS piwigo_favorites;
+CREATE TABLE piwigo_favorites
+(
+ "user_id" INTEGER default 0 NOT NULL,
+ "image_id" INTEGER default 0 NOT NULL,
+ PRIMARY KEY ("user_id","image_id")
+);
+
+
+-----------------------------------------------------------------------------
+-- piwigo_group_access
+-----------------------------------------------------------------------------
+
+DROP TABLE IF EXISTS piwigo_group_access;
+CREATE TABLE piwigo_group_access
+(
+ "group_id" INTEGER default 0 NOT NULL,
+ "cat_id" INTEGER default 0 NOT NULL,
+ PRIMARY KEY ("group_id","cat_id")
+);
+
+-----------------------------------------------------------------------------
+-- piwigo_groups
+-----------------------------------------------------------------------------
+
+DROP TABLE IF EXISTS piwigo_groups;
+CREATE TABLE piwigo_groups
+(
+ "id" INTEGER NOT NULL,
+ "name" VARCHAR(255) default '' NOT NULL,
+ "is_default" BOOLEAN default false,
+ PRIMARY KEY ("id"),
+ CONSTRAINT "groups_ui1" UNIQUE ("name")
+);
+
+-----------------------------------------------------------------------------
+-- piwigo_history
+-----------------------------------------------------------------------------
+
+DROP TABLE IF EXISTS piwigo_history;
+CREATE TABLE piwigo_history
+(
+ "id" INTEGER NOT NULL,
+ "date" DATE NOT NULL,
+ "time" TIME NOT NULL,
+ "user_id" INTEGER default 0 NOT NULL,
+ "ip" VARCHAR(15) default '' NOT NULL,
+ "section" VARCHAR(50) default NULL,
+ "category_id" INTEGER,
+ "tag_ids" VARCHAR(50),
+ "image_id" INTEGER,
+ "summarized" BOOLEAN default false,
+ "image_type" VARCHAR(50) default NULL,
+ PRIMARY KEY ("id")
+);
+
+
+CREATE INDEX "history_i1" ON "piwigo_history" ("summarized");
+
+-----------------------------------------------------------------------------
+-- piwigo_history_summary
+-----------------------------------------------------------------------------
+
+DROP TABLE IF EXISTS piwigo_history_summary;
+CREATE TABLE piwigo_history_summary
+(
+ "year" INTEGER default 0 NOT NULL,
+ "month" INTEGER,
+ "day" INTEGER,
+ "hour" INTEGER,
+ "nb_pages" INTEGER,
+ "id" INTEGER NOT NULL,
+ PRIMARY KEY ("id"),
+ CONSTRAINT "history_summary_ymdh" UNIQUE ("year","month","day","hour")
+);
+
+-----------------------------------------------------------------------------
+-- piwigo_image_category
+-----------------------------------------------------------------------------
+
+DROP TABLE IF EXISTS piwigo_image_category;
+CREATE TABLE piwigo_image_category
+(
+ "image_id" INTEGER default 0 NOT NULL,
+ "category_id" INTEGER default 0 NOT NULL,
+ "rank" INTEGER,
+ PRIMARY KEY ("image_id","category_id")
+);
+
+
+CREATE INDEX "image_category_i1" ON "piwigo_image_category" ("category_id");
+
+-----------------------------------------------------------------------------
+-- piwigo_image_tag
+-----------------------------------------------------------------------------
+
+DROP TABLE IF EXISTS piwigo_image_tag;
+CREATE TABLE piwigo_image_tag
+(
+ "image_id" INTEGER default 0 NOT NULL,
+ "tag_id" INTEGER default 0 NOT NULL,
+ PRIMARY KEY ("image_id","tag_id")
+);
+
+
+CREATE INDEX "image_tag_i1" ON "piwigo_image_tag" ("tag_id");
+
+-----------------------------------------------------------------------------
+-- piwigo_images
+-----------------------------------------------------------------------------
+
+DROP TABLE IF EXISTS piwigo_images;
+CREATE TABLE piwigo_images
+(
+ "id" INTEGER NOT NULL,
+ "file" VARCHAR(255) default '' NOT NULL,
+ "date_available" TIMESTAMP NOT NULL,
+ "date_creation" TIMESTAMP,
+ "tn_ext" VARCHAR(4) default '',
+ "name" VARCHAR(255),
+ "comment" TEXT,
+ "author" VARCHAR(255),
+ "hit" INTEGER default 0 NOT NULL,
+ "filesize" INTEGER,
+ "width" INTEGER,
+ "height" INTEGER,
+ "representative_ext" VARCHAR(4),
+ "date_metadata_update" DATE,
+ "average_rate" FLOAT,
+ "has_high" BOOLEAN default false,
+ "path" VARCHAR(255) default '' NOT NULL,
+ "storage_category_id" INTEGER,
+ "high_filesize" INTEGER,
+ "level" INTEGER default 0 NOT NULL,
+ "md5sum" CHAR(32),
+ PRIMARY KEY ("id")
+);
+
+
+CREATE INDEX "images_i2" ON "piwigo_images" ("date_available");
+
+CREATE INDEX "images_i3" ON "piwigo_images" ("average_rate");
+
+CREATE INDEX "images_i4" ON "piwigo_images" ("hit");
+
+CREATE INDEX "images_i5" ON "piwigo_images" ("date_creation");
+
+CREATE INDEX "images_i1" ON "piwigo_images" ("storage_category_id");
+
+-----------------------------------------------------------------------------
+-- piwigo_old_permalinks
+-----------------------------------------------------------------------------
+
+DROP TABLE IF EXISTS piwigo_old_permalinks;
+CREATE TABLE piwigo_old_permalinks
+(
+ "cat_id" INTEGER default 0 NOT NULL,
+ "permalink" VARCHAR(64) default '' NOT NULL,
+ "date_deleted" TIMESTAMP NOT NULL,
+ "last_hit" TIMESTAMP,
+ "hit" INTEGER default 0 NOT NULL,
+ PRIMARY KEY ("permalink")
+);
+
+
+-----------------------------------------------------------------------------
+-- piwigo_plugins
+-----------------------------------------------------------------------------
+
+DROP TABLE IF EXISTS piwigo_plugins;
+CREATE TABLE piwigo_plugins
+(
+ "id" VARCHAR(64) default '' NOT NULL,
+ "state" VARCHAR(50) default 'inactive',
+ "version" VARCHAR(64) default '0' NOT NULL,
+ PRIMARY KEY ("id")
+);
+
+
+-----------------------------------------------------------------------------
+-- piwigo_rate
+-----------------------------------------------------------------------------
+
+DROP TABLE IF EXISTS piwigo_rate;
+CREATE TABLE piwigo_rate
+(
+ "user_id" INTEGER default 0 NOT NULL,
+ "element_id" INTEGER default 0 NOT NULL,
+ "anonymous_id" VARCHAR(45) default '' NOT NULL,
+ "rate" INTEGER default 0 NOT NULL,
+ "date" DATE NOT NULL,
+ PRIMARY KEY ("user_id","element_id","anonymous_id")
+);
+
+
+-----------------------------------------------------------------------------
+-- piwigo_search
+-----------------------------------------------------------------------------
+
+DROP TABLE IF EXISTS piwigo_search;
+CREATE TABLE piwigo_search
+(
+ "id" INTEGER NOT NULL,
+ "last_seen" DATE,
+ "rules" TEXT,
+ PRIMARY KEY ("id")
+);
+
+
+-----------------------------------------------------------------------------
+-- piwigo_sessions
+-----------------------------------------------------------------------------
+
+DROP TABLE IF EXISTS piwigo_sessions;
+CREATE TABLE piwigo_sessions
+(
+ "id" VARCHAR(255) default '' NOT NULL,
+ "data" TEXT NOT NULL,
+ "expiration" TIMESTAMP NOT NULL,
+ PRIMARY KEY ("id")
+);
+
+
+-----------------------------------------------------------------------------
+-- piwigo_sites
+-----------------------------------------------------------------------------
+
+DROP TABLE IF EXISTS piwigo_sites;
+CREATE TABLE piwigo_sites
+(
+ "id" INTEGER NOT NULL,
+ "galleries_url" VARCHAR(255) default '' NOT NULL,
+ PRIMARY KEY ("id"),
+ CONSTRAINT "sites_ui1" UNIQUE ("galleries_url")
+);
+
+
+-----------------------------------------------------------------------------
+-- piwigo_stuffs
+-----------------------------------------------------------------------------
+
+DROP TABLE IF EXISTS piwigo_stuffs;
+CREATE TABLE piwigo_stuffs
+(
+ "id" INTEGER NOT NULL,
+ "pos" INTEGER NOT NULL,
+ "name" TEXT NOT NULL,
+ "descr" VARCHAR(255),
+ "type" VARCHAR(255) NOT NULL,
+ "datas" TEXT,
+ "users" VARCHAR(255),
+ "groups" VARCHAR(255),
+ "show_title" CHAR NOT NULL,
+ "on_home" CHAR NOT NULL,
+ "on_cats" CHAR NOT NULL,
+ "on_picture" CHAR NOT NULL,
+ "id_line" VARCHAR(1),
+ "width" INTEGER,
+ PRIMARY KEY ("id")
+);
+
+
+CREATE INDEX "on_home" ON "piwigo_stuffs" ("on_home");
+
+CREATE INDEX "on_cats" ON "piwigo_stuffs" ("on_cats");
+
+CREATE INDEX "on_picture" ON "piwigo_stuffs" ("on_picture");
+
+-----------------------------------------------------------------------------
+-- piwigo_tags
+-----------------------------------------------------------------------------
+
+DROP TABLE IF EXISTS piwigo_tags;
+CREATE TABLE piwigo_tags
+(
+ "id" INTEGER NOT NULL,
+ "name" VARCHAR(255) default '' NOT NULL,
+ "url_name" VARCHAR(255) default '' NOT NULL,
+ PRIMARY KEY ("id")
+);
+
+
+CREATE INDEX "tags_i1" ON "piwigo_tags" ("url_name");
+
+-----------------------------------------------------------------------------
+-- piwigo_upgrade
+-----------------------------------------------------------------------------
+
+DROP TABLE IF EXISTS piwigo_upgrade;
+CREATE TABLE piwigo_upgrade
+(
+ "id" VARCHAR(20) default '' NOT NULL,
+ "applied" TIMESTAMP NOT NULL,
+ "description" VARCHAR(255),
+ PRIMARY KEY ("id")
+);
+
+
+-----------------------------------------------------------------------------
+-- piwigo_user_access
+-----------------------------------------------------------------------------
+
+DROP TABLE IF EXISTS piwigo_user_access;
+CREATE TABLE piwigo_user_access
+(
+ "user_id" INTEGER default 0 NOT NULL,
+ "cat_id" INTEGER default 0 NOT NULL,
+ PRIMARY KEY ("user_id","cat_id")
+);
+
+
+-----------------------------------------------------------------------------
+-- piwigo_user_cache
+-----------------------------------------------------------------------------
+
+DROP TABLE IF EXISTS piwigo_user_cache;
+CREATE TABLE piwigo_user_cache
+(
+ "user_id" INTEGER default 0 NOT NULL,
+ "need_update" BOOLEAN default true,
+ "cache_update_time" INTEGER default 0 NOT NULL,
+ "forbidden_categories" TEXT,
+ "nb_total_images" INTEGER,
+ "image_access_type" VARCHAR(50) default 'NOT IN',
+ "image_access_list" TEXT,
+ PRIMARY KEY ("user_id")
+);
+
+
+-----------------------------------------------------------------------------
+-- piwigo_user_cache_categories
+-----------------------------------------------------------------------------
+
+DROP TABLE IF EXISTS piwigo_user_cache_categories;
+CREATE TABLE piwigo_user_cache_categories
+(
+ "user_id" INTEGER default 0 NOT NULL,
+ "cat_id" INTEGER default 0 NOT NULL,
+ "date_last" TIMESTAMP,
+ "max_date_last" TIMESTAMP,
+ "nb_images" INTEGER default 0 NOT NULL,
+ "count_images" INTEGER default 0,
+ "count_categories" INTEGER default 0,
+ PRIMARY KEY ("user_id","cat_id")
+);
+
+
+-----------------------------------------------------------------------------
+-- piwigo_user_feed
+-----------------------------------------------------------------------------
+
+DROP TABLE IF EXISTS piwigo_user_feed;
+CREATE TABLE piwigo_user_feed
+(
+ "id" VARCHAR(50) default '' NOT NULL,
+ "user_id" INTEGER default 0 NOT NULL,
+ "last_check" TIMESTAMP,
+ PRIMARY KEY ("id")
+);
+
+
+-----------------------------------------------------------------------------
+-- piwigo_user_group
+-----------------------------------------------------------------------------
+
+DROP TABLE IF EXISTS piwigo_user_group;
+CREATE TABLE piwigo_user_group
+(
+ "user_id" INTEGER default 0 NOT NULL,
+ "group_id" INTEGER default 0 NOT NULL,
+ PRIMARY KEY ("user_id","group_id")
+);
+
+
+-----------------------------------------------------------------------------
+-- piwigo_user_infos
+-----------------------------------------------------------------------------
+
+DROP TABLE IF EXISTS piwigo_user_infos;
+CREATE TABLE piwigo_user_infos
+(
+ "user_id" INTEGER default 0 NOT NULL,
+ "nb_image_line" INTEGER default 5 NOT NULL,
+ "nb_line_page" INTEGER default 3 NOT NULL,
+ "status" VARCHAR(50) default 'guest',
+ "adviser" BOOLEAN default false,
+ "language" VARCHAR(50) default 'en_UK' NOT NULL,
+ "maxwidth" INTEGER,
+ "maxheight" INTEGER,
+ "expand" BOOLEAN default false,
+ "show_nb_comments" BOOLEAN default false,
+ "show_nb_hits" BOOLEAN default false,
+ "recent_period" INTEGER default 7 NOT NULL,
+ "template" VARCHAR(255) default 'yoga/Sylvia' NOT NULL,
+ "registration_date" TIMESTAMP NOT NULL,
+ "enabled_high" BOOLEAN default true,
+ "level" INTEGER default 0 NOT NULL,
+ PRIMARY KEY ("user_id"),
+ CONSTRAINT "user_infos_ui1" UNIQUE ("user_id")
+);
+
+
+-----------------------------------------------------------------------------
+-- piwigo_user_mail_notification
+-----------------------------------------------------------------------------
+
+DROP TABLE IF EXISTS piwigo_user_mail_notification;
+CREATE TABLE piwigo_user_mail_notification
+(
+ "user_id" INTEGER default 0 NOT NULL,
+ "check_key" VARCHAR(16) default '' NOT NULL,
+ "enabled" BOOLEAN default false,
+ "last_send" TIMESTAMP,
+ PRIMARY KEY ("user_id"),
+ CONSTRAINT "user_mail_notification_ui1" UNIQUE ("check_key")
+);
+
+
+-----------------------------------------------------------------------------
+-- piwigo_users
+-----------------------------------------------------------------------------
+
+DROP TABLE IF EXISTS piwigo_users;
+CREATE TABLE piwigo_users
+(
+ "id" INTEGER NOT NULL,
+ "username" VARCHAR(100) default '' NOT NULL,
+ "password" VARCHAR(32),
+ "mail_address" VARCHAR(255),
+ PRIMARY KEY ("id"),
+ CONSTRAINT "users_ui1" UNIQUE ("username")
+);
+
+
+-----------------------------------------------------------------------------
+-- piwigo_comments
+-----------------------------------------------------------------------------
+
+DROP TABLE IF EXISTS piwigo_comments;
+CREATE TABLE piwigo_comments
+(
+ "id" INTEGER NOT NULL,
+ "image_id" INTEGER default 0 NOT NULL,
+ "date" TIMESTAMP NOT NULL,
+ "author" VARCHAR(255),
+ "content" TEXT,
+ "validated" BOOLEAN default false,
+ "validation_date" TIMESTAMP,
+ "author_id" INTEGER REFERENCES "piwigo_users" (id),
+ PRIMARY KEY ("id")
+);
+
+CREATE INDEX "comments_i2" ON "piwigo_comments" ("validation_date");
+CREATE INDEX "comments_i1" ON "piwigo_comments" ("image_id");
+
+-----------------------------------------------------------------------------
+-- piwigo_waiting
+-----------------------------------------------------------------------------
+
+DROP TABLE IF EXISTS piwigo_waiting;
+CREATE TABLE piwigo_waiting
+(
+ "id" INTEGER NOT NULL,
+ "storage_category_id" INTEGER default 0 NOT NULL,
+ "file" VARCHAR(255) default '' NOT NULL,
+ "username" VARCHAR(255) default '' NOT NULL,
+ "mail_address" VARCHAR(255) default '' NOT NULL,
+ "date" INTEGER default 0 NOT NULL,
+ "tn_ext" CHAR(3),
+ "validated" BOOLEAN default false,
+ "infos" TEXT,
+ PRIMARY KEY ("id")
+);
+