source: trunk/admin/maintenance.php @ 23375

Last change on this file since 23375 was 20544, checked in by plg, 12 years ago

bug 2825: add maintenance action to clean the database and avoid integrity errors

  • Property svn:eol-style set to LF
File size: 7.0 KB
RevLine 
[809]1<?php
2// +-----------------------------------------------------------------------+
[8728]3// | Piwigo - a PHP based photo gallery                                    |
[2297]4// +-----------------------------------------------------------------------+
[19703]5// | Copyright(C) 2008-2013 Piwigo Team                  http://piwigo.org |
[2297]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// +-----------------------------------------------------------------------+
[809]23
24if (!defined('PHPWG_ROOT_PATH'))
25{
26  die ("Hacking attempt!");
27}
28
[1072]29include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
30
[809]31// +-----------------------------------------------------------------------+
[1072]32// | Check Access and exit when user status is not ok                      |
33// +-----------------------------------------------------------------------+
[8765]34
[1072]35check_status(ACCESS_ADMINISTRATOR);
36
[8765]37if (isset($_GET['action']))
38{
39  check_pwg_token();
40}
41
[1072]42// +-----------------------------------------------------------------------+
[809]43// |                                actions                                |
44// +-----------------------------------------------------------------------+
45
[8126]46$action = isset($_GET['action']) ? $_GET['action'] : '';
[809]47
48switch ($action)
49{
[13001]50  case 'lock_gallery' :
51  {
52    conf_update_param('gallery_locked', 'true');
53    redirect(get_root_url().'admin.php?page=maintenance');
54    break;
55  }
56  case 'unlock_gallery' :
57  {
58    conf_update_param('gallery_locked', 'false');
59    $_SESSION['page_infos'] = array(l10n('Gallery unlocked'));
60    redirect(get_root_url().'admin.php?page=maintenance');
61    break;
62  }
[809]63  case 'categories' :
64  {
[20544]65    images_integrity();
[809]66    update_uppercats();
67    update_category('all');
68    update_global_rank();
[2890]69    invalidate_user_cache(true);
[809]70    break;
71  }
72  case 'images' :
73  {
[20544]74    images_integrity();
[809]75    update_path();
[11827]76                include_once(PHPWG_ROOT_PATH.'include/functions_rate.inc.php');
77    update_rating_score();
[20544]78    invalidate_user_cache();
[809]79    break;
80  }
[8762]81  case 'delete_orphan_tags' :
82  {
83    delete_orphan_tags();
84    break;
85  }
[20544]86  case 'user_cache' :
87  {
88    invalidate_user_cache();
89    break;
90  }
[2062]91  case 'history_detail' :
[809]92  {
93    $query = '
94DELETE
[2062]95  FROM '.HISTORY_TABLE.'
[1987]96;';
97    pwg_query($query);
[2062]98    break;
99  }
100  case 'history_summary' :
101  {
[1987]102    $query = '
103DELETE
[2062]104  FROM '.HISTORY_SUMMARY_TABLE.'
[809]105;';
106    pwg_query($query);
107    break;
108  }
109  case 'sessions' :
110  {
[1080]111    pwg_session_gc();
[809]112    break;
113  }
[833]114  case 'feeds' :
115  {
116    $query = '
117DELETE
118  FROM '.USER_FEED_TABLE.'
119  WHERE last_check IS NULL
120;';
121    pwg_query($query);
122    break;
123  }
[1111]124  case 'database' :
125  {
126    do_maintenance_all_tables();
127    break;
128  }
[2208]129  case 'c13y' :
130  {
[2232]131    include_once(PHPWG_ROOT_PATH.'admin/include/check_integrity.class.php');
132    $c13y = new check_integrity();
133    $c13y->maintenance();
[2208]134    break;
135  }
[3517]136  case 'search' :
137  {
138    $query = '
139DELETE
140  FROM '.SEARCH_TABLE.'
141;';
142    pwg_query($query);
143    break;
144  }
[12797]145  case 'compiled-templates':
[2251]146  {
[2278]147    $template->delete_compiled_templates();
[8634]148    FileCombiner::clear_combined_files();
[2251]149    break;
150  }
[12797]151  case 'derivatives':
152  {
[13074]153    clear_derivative_cache($_GET['type']);
[12797]154    break;
155  }
[809]156  default :
157  {
158    break;
159  }
160}
161
162// +-----------------------------------------------------------------------+
163// |                             template init                             |
164// +-----------------------------------------------------------------------+
165
[2530]166$template->set_filenames(array('maintenance'=>'maintenance.tpl'));
[809]167
[8765]168$url_format = get_root_url().'admin.php?page=maintenance&amp;action=%s&amp;pwg_token='.get_pwg_token();
[809]169
[13651]170$purge_urls[l10n('All')] = sprintf($url_format, 'derivatives').'&amp;type=all';
[13074]171foreach(ImageStdParams::get_defined_type_map() as $params)
172{
173  $purge_urls[ l10n($params->type) ] = sprintf($url_format, 'derivatives').'&amp;type='.$params->type;
174}
[13651]175$purge_urls[ l10n(IMG_CUSTOM) ] = sprintf($url_format, 'derivatives').'&amp;type='.IMG_CUSTOM;
[13074]176
[2251]177$template->assign(
[1111]178  array(
[8765]179    'U_MAINT_CATEGORIES' => sprintf($url_format, 'categories'),
180    'U_MAINT_IMAGES' => sprintf($url_format, 'images'),
181    'U_MAINT_ORPHAN_TAGS' => sprintf($url_format, 'delete_orphan_tags'),
[20544]182    'U_MAINT_USER_CACHE' => sprintf($url_format, 'user_cache'),
[8765]183    'U_MAINT_HISTORY_DETAIL' => sprintf($url_format, 'history_detail'),
184    'U_MAINT_HISTORY_SUMMARY' => sprintf($url_format, 'history_summary'),
185    'U_MAINT_SESSIONS' => sprintf($url_format, 'sessions'),
186    'U_MAINT_FEEDS' => sprintf($url_format, 'feeds'),
187    'U_MAINT_DATABASE' => sprintf($url_format, 'database'),
188    'U_MAINT_C13Y' => sprintf($url_format, 'c13y'),
189    'U_MAINT_SEARCH' => sprintf($url_format, 'search'),
190    'U_MAINT_COMPILED_TEMPLATES' => sprintf($url_format, 'compiled-templates'),
[12797]191    'U_MAINT_DERIVATIVES' => sprintf($url_format, 'derivatives'),
[13074]192    'purge_derivatives' => $purge_urls,
[5920]193    'U_HELP' => get_root_url().'admin/popuphelp.php?page=maintenance',
[1111]194    )
195  );
[1080]196
[13074]197
[13001]198if ($conf['gallery_locked'])
199{
200  $template->assign(
201    array(
202      'U_MAINT_UNLOCK_GALLERY' => sprintf($url_format, 'unlock_gallery'),
203      )
204    );
205}
206else
207{
208  $template->assign(
209    array(
210      'U_MAINT_LOCK_GALLERY' => sprintf($url_format, 'lock_gallery'),
211      )
212    );
213}
214
[809]215// +-----------------------------------------------------------------------+
[5745]216// | Define advanced features                                              |
217// +-----------------------------------------------------------------------+
218
219$advanced_features = array();
220
221//$advanced_features is array of array composed of CAPTION & URL
222$advanced_features = trigger_event(
223  'get_admin_advanced_features_links',
224  $advanced_features
225  );
226
227$template->assign('advanced_features', $advanced_features);
228
229// +-----------------------------------------------------------------------+
[809]230// |                           sending html code                           |
231// +-----------------------------------------------------------------------+
232
233$template->assign_var_from_handle('ADMIN_CONTENT', 'maintenance');
234?>
Note: See TracBrowser for help on using the repository browser.