source: trunk/install/db/108-database.php @ 19703

Last change on this file since 19703 was 19703, checked in by plg, 11 years ago

update Piwigo headers to 2013 (the end of the world didn't occur as expected on r12922)

File size: 4.3 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2013 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24if (!defined('PHPWG_ROOT_PATH'))
25{
26  die('Hacking attempt!');
27}
28
29$upgrade_description = 'add order parameters to bdd #2';
30
31$order_regex = '#^(( *)(id|file|name|date_available|date_creation|hit|average_rate|comment|author|filesize|width|height|high_filesize|high_width|high_height|rank) (ASC|DESC),{1}){1,}$#';
32
33// local file is writable
34if ( is_writable($local_file = PHPWG_ROOT_PATH. 'local/config/config.inc.php') )
35{
36  $order_by = str_ireplace(
37    array('order by ', 'asc', 'desc'),
38    array(null, 'ASC', 'DESC'),
39    trim($conf['order_by_inside_category'])
40    );
41   
42  // for a simple patern
43  if ( preg_match($order_regex, $order_by.',') )
44  {
45    $order_by = 'ORDER BY '.$order_by;
46    // update database
47    $query = '
48    UPDATE '.PREFIX_TABLE.'config
49      SET value = \''.preg_replace('# rank (ASC|DESC)(,?)#', null, $order_by).'\'
50      WHERE param = \'order_by\'
51    ;';
52    pwg_query($query);
53    $query = '
54    UPDATE '.PREFIX_TABLE.'config
55      SET value = \''.$order_by.'\'
56      WHERE param = \'order_by_inside_category\'
57    ';
58    pwg_query($query);
59   
60    // update local file (delete lines)
61    $local_config = file($local_file);
62    $new_local_config = array();
63    foreach ($local_config as $line)
64    {
65      if (strpos($line, 'order_by') === false)
66      {
67        $new_local_config[] = $line;
68      }
69    }
70    var_dump($new_local_config);
71    file_put_contents(
72      $local_file,
73      implode("", $new_local_config)
74      );
75  }
76  // for a complex patern
77  else
78  {
79    // update database with default param
80    $query = '
81    UPDATE '.PREFIX_TABLE.'config
82      SET value = \'ORDER BY date_available DESC, file ASC, id ASC\'
83      WHERE param = \'order_by\'
84    ;';
85    pwg_query($query);
86    $query = '
87    UPDATE '.PREFIX_TABLE.'config
88      SET value = \'ORDER BY date_available DESC, file ASC, id ASC\'
89      WHERE param = \'order_by_inside_category\'
90    ';
91    pwg_query($query);
92   
93    // update local file (rename lines)
94    $local_config = file_get_contents($local_file);
95    $new_local_config = str_replace(
96      array("['order_by']", "['order_by_inside_category']"),
97      array("['order_by_custom']", "['order_by_inside_category_custom']"),
98      $local_config
99      );
100    file_put_contents($local_file, $new_local_config);
101  }
102 
103}
104// local file is locked
105else
106{
107  // update database with default param
108  $query = '
109  UPDATE '.PREFIX_TABLE.'config
110    SET value = \'ORDER BY date_available DESC, file ASC, id ASC\'
111    WHERE param = \'order_by\'
112  ;';
113  pwg_query($query);
114  $query = '
115  UPDATE '.PREFIX_TABLE.'config
116    SET value = \'ORDER BY date_available DESC, file ASC, id ASC\'
117    WHERE param = \'order_by_inside_category\'
118  ';
119  pwg_query($query);
120}
121
122echo
123"\n"
124. $upgrade_description
125."\n"
126;
127?>
Note: See TracBrowser for help on using the repository browser.