1<?php
2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
3//
4// All Rights Reserved. See copyright.txt for details and a complete list of authors.
5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6// $Id$
7
8if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
9	header("location: index.php");
10	exit;
11}
12
13/**
14 * @param $installer
15 */
16function upgrade_20180921_php_upgrade_fix_from_older_tiki($installer)
17{
18	// Fix upgrade from 9.x
19	$installer->query('ALTER TABLE `tiki_secdb` DROP PRIMARY KEY;'); // it might not be set
20	$installer->query('ALTER TABLE `tiki_secdb` ADD PRIMARY KEY (`filename`(215),`tiki_version`(40));');
21
22	// Fix upgrade from 12.x
23	$tablesToRename = [
24		'metrics_assigned',
25		'metrics_metric',
26		'metrics_tab',
27		'tiki_users_score',
28	];
29
30	foreach ($tablesToRename as $table) {
31		if (! empty($installer->query("SHOW TABLES LIKE '" . $table . "';")->result)) {
32			$installer->query('RENAME TABLE `' . $table . '` TO `zzz_unused_' . $table . '`;');
33		}
34	}
35
36	if (! empty($installer->query("SHOW COLUMNS FROM `tiki_pages` LIKE 'status';")->result)) {
37		$installer->query('ALTER TABLE tiki_pages DROP COLUMN status;');
38	}
39	if (! empty($installer->query("SHOW COLUMNS FROM `tiki_history` LIKE 'status';")->result)) {
40		$installer->query('ALTER TABLE tiki_history DROP COLUMN status;');
41	}
42
43	// Fix upgrade from 15.x
44	if (! empty($installer->query("SHOW COLUMNS FROM `users_users` LIKE 'challenge';")->result)) {
45		$installer->query('ALTER TABLE users_users DROP COLUMN challenge;');
46	}
47}
48