1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Elgg upgrade library. |
4
|
|
|
* Contains code for handling versioning and upgrades. |
5
|
|
|
* |
6
|
|
|
* @package Elgg.Core |
7
|
|
|
* @subpackage Upgrade |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Saves the processed upgrades to a dataset. |
12
|
|
|
* |
13
|
|
|
* @param array $processed_upgrades An array of processed upgrade filenames |
14
|
|
|
* (not the path, just the file) |
15
|
|
|
* @return bool |
16
|
|
|
* @access private |
17
|
|
|
* |
18
|
|
|
* @todo this is still required because of the hack in the 2011010101 upgrade |
19
|
|
|
*/ |
20
|
|
|
function elgg_set_processed_upgrades(array $processed_upgrades) { |
21
|
|
|
$processed_upgrades = array_unique($processed_upgrades); |
22
|
|
|
return datalist_set('processed_upgrades', serialize($processed_upgrades)); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Returns the version of the upgrade filename. |
27
|
|
|
* |
28
|
|
|
* @param string $filename The upgrade filename. No full path. |
29
|
|
|
* @return int|false |
30
|
|
|
* @since 1.8.0 |
31
|
|
|
* @access private |
32
|
|
|
* @todo used by elgg_get_upgrade_files |
33
|
|
|
*/ |
34
|
|
View Code Duplication |
function elgg_get_upgrade_file_version($filename) { |
35
|
|
|
preg_match('/^([0-9]{10})([\.a-z0-9-_]+)?\.(php)$/i', $filename, $matches); |
36
|
|
|
|
37
|
|
|
if (isset($matches[1])) { |
38
|
|
|
return (int) $matches[1]; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
return false; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Returns a list of upgrade files relative to the $upgrade_path dir. |
46
|
|
|
* |
47
|
|
|
* @param string $upgrade_path The directory that has upgrade scripts |
48
|
|
|
* @return array|false |
49
|
|
|
* @access private |
50
|
|
|
* |
51
|
|
|
* @todo the wire and groups plugins and the installer are using this |
52
|
|
|
*/ |
53
|
|
|
function elgg_get_upgrade_files($upgrade_path = null) { |
54
|
|
|
if (!$upgrade_path) { |
|
|
|
|
55
|
|
|
$upgrade_path = elgg_get_root_path() . 'engine/lib/upgrades/'; |
56
|
|
|
} |
57
|
|
|
$upgrade_path = sanitise_filepath($upgrade_path); |
58
|
|
|
$handle = opendir($upgrade_path); |
59
|
|
|
|
60
|
|
|
if (!$handle) { |
61
|
|
|
return false; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$upgrade_files = array(); |
65
|
|
|
|
66
|
|
View Code Duplication |
while ($upgrade_file = readdir($handle)) { |
67
|
|
|
// make sure this is a well formed upgrade. |
68
|
|
|
if (is_dir($upgrade_path . '$upgrade_file')) { |
69
|
|
|
continue; |
70
|
|
|
} |
71
|
|
|
$upgrade_version = elgg_get_upgrade_file_version($upgrade_file); |
72
|
|
|
if (!$upgrade_version) { |
|
|
|
|
73
|
|
|
continue; |
74
|
|
|
} |
75
|
|
|
$upgrade_files[] = $upgrade_file; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
sort($upgrade_files); |
79
|
|
|
|
80
|
|
|
return $upgrade_files; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Unlocks upgrade. |
85
|
|
|
* |
86
|
|
|
* @access private |
87
|
|
|
* |
88
|
|
|
* @todo the hack in the 2011010101 upgrade requires this |
89
|
|
|
*/ |
90
|
|
|
function _elgg_upgrade_unlock() { |
91
|
|
|
global $CONFIG; |
92
|
|
|
delete_data("drop table {$CONFIG->dbprefix}upgrade_lock"); |
93
|
|
|
elgg_log('Upgrade unlocked.', 'NOTICE'); |
94
|
|
|
} |
95
|
|
|
|
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: