PageRenderTime 48ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/fsn-site-central/mediatheque/install/upgrade_1.3.1.php

https://gitlab.com/team_fsn/fsn-php
PHP | 613 lines | 502 code | 73 blank | 38 comment | 13 complexity | 4f4b9f308f75fcb1c44b45dd4790e79b MD5 | raw file
  1. <?php
  2. // +-----------------------------------------------------------------------+
  3. // | Piwigo - a PHP based photo gallery |
  4. // +-----------------------------------------------------------------------+
  5. // | Copyright(C) 2008-2016 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. /**
  24. * Upgrade from 1.3.x (x >= 1) to 1.4.0
  25. */
  26. if (!defined('PHPWG_ROOT_PATH'))
  27. {
  28. die ('This page cannot be loaded directly, load upgrade.php');
  29. }
  30. else
  31. {
  32. if (!defined('PHPWG_IN_UPGRADE') or !PHPWG_IN_UPGRADE)
  33. {
  34. die ('Hacking attempt!');
  35. }
  36. }
  37. // save data before deletion
  38. $query = '
  39. SELECT prefix_thumbnail, mail_webmaster
  40. FROM '.PREFIX_TABLE.'config
  41. ;';
  42. $save = pwg_db_fetch_assoc(pwg_query($query));
  43. $queries = array(
  44. "
  45. DROP TABLE phpwebgallery_config
  46. ;",
  47. "
  48. CREATE TABLE phpwebgallery_config (
  49. param varchar(40) NOT NULL default '',
  50. value varchar(255) default NULL,
  51. comment varchar(255) default NULL,
  52. PRIMARY KEY (param)
  53. ) ENGINE=MyISAM COMMENT='configuration table'
  54. ;",
  55. "
  56. ALTER TABLE phpwebgallery_categories
  57. CHANGE COLUMN site_id site_id tinyint(4) unsigned default '1'
  58. ;",
  59. "
  60. ALTER TABLE phpwebgallery_categories
  61. ADD COLUMN commentable enum('true','false') NOT NULL default 'true'
  62. ;",
  63. "
  64. ALTER TABLE phpwebgallery_categories
  65. ADD COLUMN global_rank varchar(255) default NULL
  66. ;",
  67. "
  68. ALTER TABLE phpwebgallery_categories
  69. ADD INDEX categories_i2 (id_uppercat)
  70. ;",
  71. "
  72. ALTER TABLE phpwebgallery_comments
  73. ADD COLUMN date_temp int(11) unsigned
  74. ;",
  75. "
  76. UPDATE phpwebgallery_comments
  77. SET date_temp = date
  78. ;",
  79. "
  80. ALTER TABLE phpwebgallery_comments
  81. CHANGE COLUMN date date datetime NOT NULL default '0000-00-00 00:00:00'
  82. ;",
  83. "
  84. UPDATE phpwebgallery_comments
  85. SET date = FROM_UNIXTIME(date_temp)
  86. ;",
  87. "
  88. ALTER TABLE phpwebgallery_comments
  89. DROP COLUMN date_temp
  90. ;",
  91. "
  92. ALTER TABLE phpwebgallery_favorites
  93. DROP INDEX user_id
  94. ;",
  95. "
  96. ALTER TABLE phpwebgallery_favorites
  97. ADD PRIMARY KEY (user_id,image_id)
  98. ;",
  99. "
  100. ALTER TABLE phpwebgallery_history
  101. ADD COLUMN date_temp int(11) unsigned
  102. ;",
  103. "
  104. UPDATE phpwebgallery_history
  105. SET date_temp = date
  106. ;",
  107. "
  108. ALTER TABLE phpwebgallery_history
  109. CHANGE COLUMN date date datetime NOT NULL default '0000-00-00 00:00:00'
  110. ;",
  111. "
  112. UPDATE phpwebgallery_history
  113. SET date = FROM_UNIXTIME(date_temp)
  114. ;",
  115. "
  116. ALTER TABLE phpwebgallery_history
  117. DROP COLUMN date_temp
  118. ;",
  119. "
  120. ALTER TABLE phpwebgallery_history
  121. ADD INDEX history_i1 (date)
  122. ;",
  123. "
  124. ALTER TABLE phpwebgallery_image_category
  125. ADD INDEX image_category_i1 (image_id),
  126. ADD INDEX image_category_i2 (category_id)
  127. ;",
  128. "
  129. ALTER TABLE phpwebgallery_images
  130. CHANGE COLUMN tn_ext tn_ext varchar(4) default ''
  131. ;",
  132. "
  133. ALTER TABLE phpwebgallery_images
  134. ADD COLUMN path varchar(255) NOT NULL default ''
  135. ;",
  136. "
  137. ALTER TABLE phpwebgallery_images
  138. ADD COLUMN date_metadata_update date default NULL
  139. ;",
  140. "
  141. ALTER TABLE phpwebgallery_images
  142. ADD COLUMN average_rate float(5,2) unsigned default NULL
  143. ;",
  144. "
  145. ALTER TABLE phpwebgallery_images
  146. ADD COLUMN representative_ext varchar(4) default NULL
  147. ;",
  148. "
  149. ALTER TABLE phpwebgallery_images
  150. DROP INDEX storage_category_id
  151. ;",
  152. "
  153. ALTER TABLE phpwebgallery_images
  154. ADD INDEX images_i1 (storage_category_id)
  155. ;",
  156. "
  157. ALTER TABLE phpwebgallery_images
  158. ADD INDEX images_i2 (date_available)
  159. ;",
  160. "
  161. ALTER TABLE phpwebgallery_images
  162. ADD INDEX images_i3 (average_rate)
  163. ;",
  164. "
  165. ALTER TABLE phpwebgallery_images
  166. ADD INDEX images_i4 (hit)
  167. ;",
  168. "
  169. ALTER TABLE phpwebgallery_images
  170. ADD INDEX images_i5 (date_creation)
  171. ;",
  172. "
  173. ALTER TABLE phpwebgallery_sessions
  174. DROP COLUMN ip
  175. ;",
  176. "
  177. ALTER TABLE phpwebgallery_sessions
  178. ADD COLUMN expiration_temp int(11) unsigned
  179. ;",
  180. "
  181. UPDATE phpwebgallery_sessions
  182. SET expiration_temp = expiration
  183. ;",
  184. "
  185. ALTER TABLE phpwebgallery_sessions
  186. CHANGE COLUMN expiration expiration datetime NOT NULL default '0000-00-00 00:00:00'
  187. ;",
  188. "
  189. UPDATE phpwebgallery_sessions
  190. SET expiration = FROM_UNIXTIME(expiration_temp)
  191. ;",
  192. "
  193. ALTER TABLE phpwebgallery_sessions
  194. DROP COLUMN expiration_temp
  195. ;",
  196. "
  197. ALTER TABLE phpwebgallery_sites
  198. DROP INDEX galleries_url
  199. ;",
  200. "
  201. ALTER TABLE phpwebgallery_sites
  202. ADD UNIQUE sites_ui1 (galleries_url)
  203. ;",
  204. "
  205. DROP TABLE phpwebgallery_user_category
  206. ;",
  207. "
  208. ALTER TABLE phpwebgallery_users
  209. DROP COLUMN long_period
  210. ;",
  211. "
  212. ALTER TABLE phpwebgallery_users
  213. DROP COLUMN short_period
  214. ;",
  215. "
  216. ALTER TABLE phpwebgallery_users
  217. ADD COLUMN recent_period tinyint(3) unsigned NOT NULL default '7'
  218. ;",
  219. "
  220. ALTER TABLE phpwebgallery_users
  221. DROP INDEX username
  222. ;",
  223. "
  224. ALTER TABLE phpwebgallery_users
  225. ADD UNIQUE users_ui1 (username)
  226. ;",
  227. "
  228. CREATE TABLE phpwebgallery_rate (
  229. user_id smallint(5) unsigned NOT NULL default '0',
  230. element_id mediumint(8) unsigned NOT NULL default '0',
  231. rate tinyint(2) unsigned NOT NULL default '0',
  232. PRIMARY KEY (user_id,element_id)
  233. ) ENGINE=MyISAM
  234. ;",
  235. "
  236. CREATE TABLE phpwebgallery_user_forbidden (
  237. user_id smallint(5) unsigned NOT NULL default '0',
  238. need_update enum('true','false') NOT NULL default 'true',
  239. forbidden_categories text,
  240. PRIMARY KEY (user_id)
  241. ) ENGINE=MyISAM
  242. ;",
  243. "
  244. UPDATE phpwebgallery_users
  245. SET language = 'en_UK.iso-8859-1'
  246. , template = 'default'
  247. ;",
  248. "
  249. DELETE FROM phpwebgallery_user_access
  250. ;",
  251. "
  252. DELETE FROM phpwebgallery_group_access
  253. ;"
  254. );
  255. foreach ($queries as $query)
  256. {
  257. $query = str_replace('phpwebgallery_', PREFIX_TABLE, $query);
  258. pwg_query($query);
  259. }
  260. //
  261. // check indexes
  262. //
  263. $indexes_of = array(
  264. 'categories' => array(
  265. 'categories_i2' => array(
  266. 'columns' => array('id_uppercat'),
  267. 'unique' => false,
  268. )
  269. ),
  270. 'image_category' => array(
  271. 'image_category_i1' => array(
  272. 'columns' => array('image_id'),
  273. 'unique' => false,
  274. ),
  275. 'image_category_i2' => array(
  276. 'columns' => array('category_id'),
  277. 'unique' => false,
  278. ),
  279. ),
  280. );
  281. foreach (array_keys($indexes_of) as $table)
  282. {
  283. $existing_indexes = array();
  284. $query = '
  285. SHOW INDEX
  286. FROM '.PREFIX_TABLE.$table.'
  287. ;';
  288. $result = pwg_query($query);
  289. while ($row = pwg_db_fetch_assoc($result))
  290. {
  291. if ($row['Key_name'] != 'PRIMARY')
  292. {
  293. if (!in_array($row['Key_name'], array_keys($indexes_of[$table])))
  294. {
  295. $query = '
  296. ALTER TABLE '.PREFIX_TABLE.$table.'
  297. DROP INDEX '.$row['Key_name'].'
  298. ;';
  299. pwg_query($query);
  300. }
  301. else
  302. {
  303. array_push($existing_indexes, $row['Key_name']);
  304. }
  305. }
  306. }
  307. foreach ($indexes_of[$table] as $index_name => $index)
  308. {
  309. if (!in_array($index_name, $existing_indexes))
  310. {
  311. $query = '
  312. ALTER TABLE '.PREFIX_TABLE.$table.'
  313. ADD '.($index['unique'] ? 'UNIQUE' : 'INDEX').' '
  314. .$index_name.' ('.implode(',', $index['columns']).')
  315. ;';
  316. pwg_query($query);
  317. }
  318. }
  319. }
  320. //
  321. // insert params in new configuration table
  322. //
  323. $params = array(
  324. array(
  325. 'param' => 'prefix_thumbnail',
  326. 'value' => $save['prefix_thumbnail'],
  327. 'comment' => 'thumbnails filename prefix'
  328. ),
  329. array(
  330. 'param' => 'mail_webmaster',
  331. 'value' => $save['mail_webmaster'],
  332. 'comment' => 'webmaster mail'
  333. ),
  334. array(
  335. 'param' => 'default_language',
  336. 'value' => 'en_UK.iso-8859-1',
  337. 'comment' => 'Default gallery language'
  338. ),
  339. array(
  340. 'param' => 'default_template',
  341. 'value' => 'default',
  342. 'comment' => 'Default gallery style'
  343. ),
  344. array(
  345. 'param' => 'default_maxwidth',
  346. 'value' => '',
  347. 'comment' => 'maximum width authorized for displaying images'
  348. ),
  349. array(
  350. 'param' => 'default_maxheight',
  351. 'value' => '',
  352. 'comment' => 'maximum height authorized for the displaying images'
  353. ),
  354. array(
  355. 'param' => 'nb_comment_page',
  356. 'value' => '10',
  357. 'comment' => 'number of comments to display on each page'
  358. ),
  359. array(
  360. 'param' => 'upload_maxfilesize',
  361. 'value' => '150',
  362. 'comment' => 'maximum filesize for the uploaded pictures'
  363. ),
  364. array(
  365. 'param' => 'upload_maxwidth',
  366. 'value' => '800',
  367. 'comment' => 'maximum width authorized for the uploaded images'
  368. ),
  369. array(
  370. 'param' => 'upload_maxheight',
  371. 'value' => '600',
  372. 'comment' => 'maximum height authorized for the uploaded images'
  373. ),
  374. array(
  375. 'param' => 'upload_maxwidth_thumbnail',
  376. 'value' => '150',
  377. 'comment' => 'maximum width authorized for the uploaded thumbnails'
  378. ),
  379. array(
  380. 'param' => 'upload_maxheight_thumbnail',
  381. 'value' => '100',
  382. 'comment' => 'maximum height authorized for the uploaded thumbnails'
  383. ),
  384. array(
  385. 'param' => 'log',
  386. 'value' => 'false',
  387. 'comment' => 'keep an history of visits on your website'
  388. ),
  389. array(
  390. 'param' => 'comments_validation',
  391. 'value' => 'false',
  392. 'comment' => 'administrators validate users comments before becoming visible'
  393. ),
  394. array(
  395. 'param' => 'comments_forall',
  396. 'value' => 'false',
  397. 'comment' => 'even guest not registered can post comments'
  398. ),
  399. array(
  400. 'param' => 'mail_notification',
  401. 'value' => 'false',
  402. 'comment' => 'automated mail notification for adminsitrators'
  403. ),
  404. array(
  405. 'param' => 'nb_image_line',
  406. 'value' => '5',
  407. 'comment' => 'Number of images displayed per row'
  408. ),
  409. array(
  410. 'param' => 'nb_line_page',
  411. 'value' => '3',
  412. 'comment' => 'Number of rows displayed per page'
  413. ),
  414. array(
  415. 'param' => 'recent_period',
  416. 'value' => '7',
  417. 'comment' => 'Period within which pictures are displayed as new (in days)'
  418. ),
  419. array(
  420. 'param' => 'auto_expand',
  421. 'value' => 'false',
  422. 'comment' => 'Auto expand of the category tree'
  423. ),
  424. array(
  425. 'param' => 'show_nb_comments',
  426. 'value' => 'false',
  427. 'comment' => 'Show the number of comments under the thumbnails'
  428. ),
  429. array(
  430. 'param' => 'use_iptc',
  431. 'value' => 'false',
  432. 'comment' => 'Use IPTC data during database synchronization with files metadata'
  433. ),
  434. array(
  435. 'param' => 'use_exif',
  436. 'value' => 'false',
  437. 'comment' => 'Use EXIF data during database synchronization with files metadata'
  438. ),
  439. array(
  440. 'param' => 'show_iptc',
  441. 'value' => 'false',
  442. 'comment' => 'Show IPTC metadata on picture.php if asked by user'
  443. ),
  444. array(
  445. 'param' => 'show_exif',
  446. 'value' => 'true',
  447. 'comment' => 'Show EXIF metadata on picture.php if asked by user'
  448. ),
  449. array(
  450. 'param' => 'authorize_remembering',
  451. 'value' => 'true',
  452. 'comment' => 'Authorize users to be remembered, see $conf{remember_me_length}'
  453. ),
  454. array(
  455. 'param' => 'gallery_locked',
  456. 'value' => 'false',
  457. 'comment' => 'Lock your gallery temporary for non admin users'
  458. ),
  459. );
  460. mass_inserts(
  461. CONFIG_TABLE,
  462. array_keys($params[0]),
  463. $params
  464. );
  465. // refresh calculated datas
  466. update_global_rank();
  467. update_category();
  468. // update calculated field "images.path"
  469. $cat_ids = array();
  470. $query = '
  471. SELECT DISTINCT(storage_category_id) AS unique_storage_category_id
  472. FROM '.IMAGES_TABLE.'
  473. ;';
  474. $result = pwg_query($query);
  475. while ($row = pwg_db_fetch_assoc($result))
  476. {
  477. array_push($cat_ids, $row['unique_storage_category_id']);
  478. }
  479. $fulldirs = get_fulldirs($cat_ids);
  480. foreach ($cat_ids as $cat_id)
  481. {
  482. $query = '
  483. UPDATE '.IMAGES_TABLE.'
  484. SET path = CONCAT(\''.$fulldirs[$cat_id].'\',\'/\',file)
  485. WHERE storage_category_id = '.$cat_id.'
  486. ;';
  487. pwg_query($query);
  488. }
  489. // all sub-categories of private categories become private
  490. $cat_ids = array();
  491. $query = '
  492. SELECT id
  493. FROM '.CATEGORIES_TABLE.'
  494. WHERE status = \'private\'
  495. ;';
  496. $result = pwg_query($query);
  497. while ($row = pwg_db_fetch_assoc($result))
  498. {
  499. array_push($cat_ids, $row['id']);
  500. }
  501. if (count($cat_ids) > 0)
  502. {
  503. $privates = get_subcat_ids($cat_ids);
  504. $query = '
  505. UPDATE '.CATEGORIES_TABLE.'
  506. SET status = \'private\'
  507. WHERE id IN ('.implode(',', $privates).')
  508. ;';
  509. pwg_query($query);
  510. }
  511. // load the config file
  512. $config_file = PHPWG_ROOT_PATH.'local/config/database.inc.php';
  513. $config_file_contents = @file_get_contents($config_file);
  514. if ($config_file_contents === false)
  515. {
  516. die('CANNOT LOAD '.$config_file);
  517. }
  518. $php_end_tag = strrpos($config_file_contents, '?'.'>');
  519. if ($php_end_tag === false)
  520. {
  521. die('CANNOT FIND PHP END TAG IN '.$config_file);
  522. }
  523. if (!is_writable($config_file))
  524. {
  525. die('FILE NOT WRITABLE '.$config_file);
  526. }
  527. // changes to write in database.inc.php
  528. array_push($mysql_changes, 'define(\'PHPWG_INSTALLED\', true);');
  529. // Send infos
  530. $page['infos'] = array_merge(
  531. $page['infos'],
  532. array(
  533. l10n('All sub-albums of private albums become private'),
  534. l10n('User permissions and group permissions have been erased'),
  535. l10n('Only thumbnails prefix and webmaster mail address have been saved from previous configuration')
  536. )
  537. );
  538. // now we upgrade from 1.4.0
  539. include_once(PHPWG_ROOT_PATH.'install/upgrade_1.4.0.php');
  540. ?>