source: trunk/admin/include/functions_install.inc.php @ 26946

Last change on this file since 26946 was 26946, checked in by mistic100, 10 years ago

feature 2999; docblocks for history, install and metadata

File size: 3.7 KB
RevLine 
[4410]1<?php
2// +-----------------------------------------------------------------------+
[8728]3// | Piwigo - a PHP based photo gallery                                    |
[4410]4// +-----------------------------------------------------------------------+
[26461]5// | Copyright(C) 2008-2014 Piwigo Team                  http://piwigo.org |
[4410]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
24/**
[26946]25 * @package functions\admin\install
26 */
27
28
29/**
30 * Loads a SQL file and executes all queries.
[4410]31 * Before executing a query, $replaced is... replaced by $replacing. This is
32 * useful when the SQL file contains generic words. Drop table queries are
33 * not executed.
34 *
[26946]35 * @param string $filepath
36 * @param string $replaced
37 * @param string $replacing
[4410]38 */
[5982]39function execute_sqlfile($filepath, $replaced, $replacing, $dblayer)
[4410]40{
41  $sql_lines = file($filepath);
42  $query = '';
43  foreach ($sql_lines as $sql_line)
44  {
45    $sql_line = trim($sql_line);
46    if (preg_match('/(^--|^$)/', $sql_line))
47    {
48      continue;
49    }
50    $query.= ' '.$sql_line;
51    // if we reached the end of query, we execute it and reinitialize the
52    // variable "query"
53    if (preg_match('/;$/', $sql_line))
54    {
55      $query = trim($query);
56      $query = str_replace($replaced, $replacing, $query);
57      // we don't execute "DROP TABLE" queries
58      if (!preg_match('/^DROP TABLE/i', $query))
59      {
[5982]60        if ('mysql' == $dblayer)
[4410]61        {
62          if ( preg_match('/^(CREATE TABLE .*)[\s]*;[\s]*/im', $query, $matches) )
63          {
[5982]64            $query = $matches[1].' DEFAULT CHARACTER SET utf8'.';';
[4410]65          }
66        }
67        pwg_query($query);
68      }
69      $query = '';
70    }
71  }
72}
73
74/**
[5982]75 * Automatically activate all core themes in the "themes" directory.
[5340]76 */
[5982]77function activate_core_themes()
[5340]78{
79  include_once(PHPWG_ROOT_PATH.'admin/include/themes.class.php');
80  $themes = new themes();
81  foreach ($themes->fs_themes as $theme_id => $fs_theme)
82  {
[25278]83    if (in_array($theme_id, array('elegant', 'smartpocket')))
[5982]84    {
85      $themes->perform_action('activate', $theme_id);
86    }
[5340]87  }
88}
[5384]89
[26946]90/**
91 * Connect to database during installation. Uses $_POST.
92 *
93 * @param array &$infos - populated with infos
94 * @param array &$errors - populated with errors
95 */
[5387]96function install_db_connect(&$infos, &$errors)
[5384]97{
98  try
99  {
[20720]100    pwg_db_connect($_POST['dbhost'], $_POST['dbuser'],
101                   $_POST['dbpasswd'], $_POST['dbname']);
102    pwg_db_check_version();
[5384]103  }
104  catch (Exception $e)
105  {
[25018]106    $errors[] = l10n($e->getMessage());
[5384]107  }
108}
[26946]109
[4410]110?>
Note: See TracBrowser for help on using the repository browser.