forked from NorHei/multilingual
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upgrade.php
42 lines (36 loc) · 1.46 KB
/
upgrade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
//no direct file access
if (count(get_included_files()) ==1) {
$z="HTTP/1.0 404 Not Found";
header($z);
die($z);
}
include('lang.functions.php');
// Work-out if we should check for existing page_code
$sql = 'DESCRIBE `'.TABLE_PREFIX.'pages` `page_code`';
$field_sql = $database->query($sql);
$field_set = $field_sql->numRows();
// $field_set = $database->field_add('page_code', 'pages', 'INT(11) NOT NULL AFTER `modified_by`');
// extract page_id from old format
$pattern = '/(?<=_)([0-9]{1,11})/s';
$format = $field_sql->fetchRow(MYSQLI_ASSOC) ;
// upgrade only if old format
if ($format['Type'] == 'varchar(255)') {
$sql = 'SELECT `page_code`,`page_id` FROM `'.TABLE_PREFIX.'pages` ORDER BY `page_id`';
$query_code = $database->query($sql);
while ($page = $query_code->fetchRow(MYSQLI_ASSOC)) {
preg_match($pattern, $page['page_code'], $array);
$page_code = $array[0];
$page_id = $page['page_id'];
$sql = 'UPDATE `'.TABLE_PREFIX.'pages` SET ';
$sql .= (empty($array[0])) ? '`page_code` = 0 ' : '`page_code` = '.$page_code.' ';
$sql .= 'WHERE `page_id` = '.$page_id;
$database->query($sql);
}
$sql = 'ALTER TABLE `'.TABLE_PREFIX.'pages` MODIFY COLUMN `page_code` INT(11) NOT NULL';
$database->query($sql);
}
//
$directory = dirname(__FILE__).'/'.'info.php';
// update entry in table addons to new version
load_module($directory, $install = false);