source: trunk/install/db/110-database.php @ 17914

Last change on this file since 17914 was 12922, checked in by mistic100, 13 years ago

update Piwigo headers to 2012, last change before the expected (or not) apocalypse

File size: 3.6 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2012 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
24defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
25
26$upgrade_description = 'Move "gallery_url" parameter from config table to local configuration file';
27
28include_once(PHPWG_ROOT_PATH.'include/constants.php');
29
30if (!isset($page))
31{
32  $page = array();
33}
34
35if (!isset($page['errors']))
36{
37  $page['errors'] = array();
38}
39
40$query = '
41SELECT
42    value
43  FROM '.CONFIG_TABLE.'
44  WHERE param =\'gallery_url\'
45;';
46list($gallery_url) = pwg_db_fetch_row(pwg_query($query));
47
48if (!empty($gallery_url))
49{
50  // let's try to write it in the local configuration file
51  $local_conf = PHPWG_ROOT_PATH. 'local/config/config.inc.php';
52  if (isset($conf['local_dir_site']))
53  {
54    $local_conf = PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'config/config.inc.php';
55  }
56
57  $conf_line = '$conf[\'gallery_url\'] = \''.$gallery_url.'\';';
58
59  if (!is_file($local_conf))
60  {
61    $config_file_contents_new = "<?php\n".$conf_line."\n?>";
62  }
63  else
64  {
65    // we have to update the local conf
66    $config_file_contents = @file_get_contents($local_conf);
67    if ($config_file_contents === false)
68    {
69      $error = 'Cannot load '.$local_conf.', add by hand: '.$conf_line;
70     
71      array_push($page['errors'], $error);
72      echo $error;
73    }
74    else
75    {
76      $php_end_tag = strrpos($config_file_contents, '?'.'>');
77      if ($php_end_tag === false)
78      {
79        // the file is empty
80        $config_file_contents_new = "<?php\n".$conf_line."\n?>";
81      }
82      else
83      {
84        $config_file_contents_new =
85          substr($config_file_contents, 0, $php_end_tag) . "\n"
86          .$conf_line."\n"
87          .substr($config_file_contents, $php_end_tag)
88          ;
89      }
90    }
91  }
92
93  if (isset($config_file_contents_new))
94  {
95    if (!@file_put_contents($local_conf, $config_file_contents_new))
96    {
97      $error = 'Cannot write into local configuration file '.$local_conf.', add by hand: '.$conf_line;
98     
99      array_push($page['errors'], $error);
100      echo $error;
101    }
102  }
103}
104
105$query = '
106DELETE
107  FROM '.CONFIG_TABLE.'
108  WHERE param =\'gallery_url\'
109;';
110pwg_query($query);
111
112echo
113"\n"
114. $upgrade_description
115."\n"
116;
117?>
Note: See TracBrowser for help on using the repository browser.