Skip to content

Commit 7334d4d

Browse files
committed
Merged revision 4125 from stable branch.
1 parent 8d83c54 commit 7334d4d

File tree

4 files changed

+64
-5
lines changed

4 files changed

+64
-5
lines changed

install/install.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
error_reporting(E_ALL|E_STRICT);
3636

37+
define('INSTALLER_RUN', true);
38+
3739
//** The banner on the command line
3840
echo "\n\n".str_repeat('-',80)."\n";
3941
echo " _____ ___________ _____ __ _ ____

install/lib/update.lib.php

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@
2727
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828
*/
2929

30+
//* Installer patch stub class
31+
class installer_patch_update {
32+
protected function onBeforeSQL() {
33+
}
34+
protected function onAfterSQL() {
35+
}
36+
}
37+
38+
//* DB dump function
3039
function prepareDBDump() {
3140
global $conf;
3241

@@ -151,16 +160,39 @@ function updateDbAndIni() {
151160
$found = true;
152161
while($found == true) {
153162
$next_db_version = intval($current_db_version + 1);
154-
$patch_filename = realpath(dirname(__FILE__).'/../').'/sql/incremental/upd_'.str_pad($next_db_version, 4, '0', STR_PAD_LEFT).'.sql';
155-
if(is_file($patch_filename)) {
163+
$sql_patch_filename = realpath(dirname(__FILE__).'/../').'/sql/incremental/upd_'.str_pad($next_db_version, 4, '0', STR_PAD_LEFT).'.sql';
164+
$php_patch_filename = realpath(dirname(__FILE__).'/../').'/patches/upd_'.str_pad($next_db_version, 4, '0', STR_PAD_LEFT).'.php';
165+
166+
if(is_file($sql_patch_filename)) {
167+
168+
//* Load php patch file and instantiate object
169+
if(is_file($php_patch_filename)) {
170+
$php_patch_class_name = 'upd_'.str_pad($next_db_version, 4, '0', STR_PAD_LEFT);
171+
include_once($php_patch_filename);
172+
$php_patch = new $php_patch_class_name;
173+
}
174+
175+
//* Exec onBeforeSQL function
176+
if(isset($php_patch) && is_object($php_patch)) {
177+
$php_patch->onBeforeSQL();
178+
swriteln($inst->lng('Executing PHP patch file').': '.$php_patch_filename);
179+
}
180+
156181
//* Load patch file into database
157182
if( !empty($conf["mysql"]["admin_password"]) ) {
158-
system("mysql --default-character-set=".escapeshellarg($conf['mysql']['charset'])." --force -h ".escapeshellarg($conf['mysql']['host'])." -u ".escapeshellarg($conf['mysql']['admin_user'])." -p".escapeshellarg($conf['mysql']['admin_password'])." ".escapeshellarg($conf['mysql']['database'])." < ".$patch_filename);
183+
system("mysql --default-character-set=".escapeshellarg($conf['mysql']['charset'])." --force -h ".escapeshellarg($conf['mysql']['host'])." -u ".escapeshellarg($conf['mysql']['admin_user'])." -p".escapeshellarg($conf['mysql']['admin_password'])." ".escapeshellarg($conf['mysql']['database'])." < ".$sql_patch_filename);
159184
} else {
160-
system("mysql --default-character-set=".escapeshellarg($conf['mysql']['charset'])." --force -h ".escapeshellarg($conf['mysql']['host'])." -u ".escapeshellarg($conf['mysql']['admin_user'])." ".escapeshellarg($conf['mysql']['database'])." < ".$patch_filename);
185+
system("mysql --default-character-set=".escapeshellarg($conf['mysql']['charset'])." --force -h ".escapeshellarg($conf['mysql']['host'])." -u ".escapeshellarg($conf['mysql']['admin_user'])." ".escapeshellarg($conf['mysql']['database'])." < ".$sql_patch_filename);
186+
}
187+
swriteln($inst->lng('Loading SQL patch file').': '.$sql_patch_filename);
188+
189+
//* Exec onAfterSQL function
190+
if(isset($php_patch) && is_object($php_patch)) {
191+
$php_patch->onAfterSQL();
161192
}
162-
swriteln($inst->lng('Loading SQL patch file').': '.$patch_filename);
193+
163194
$current_db_version = $next_db_version;
195+
if(isset($php_patch)) unset($php_patch);
164196
} else {
165197
$found = false;
166198
}
@@ -332,4 +364,6 @@ function updateDbAndIni() {
332364
unset($new_ini);
333365
}
334366

367+
368+
335369
?>

install/patches/upd_0001.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
if(!defined('INSTALLER_RUN')) die('Patch update file access violation.');
4+
5+
/*
6+
Example installer patch update class. the classname must match
7+
the php and the sql patch update filename. The php patches are
8+
only executed when a corresponding sql patch exists.
9+
*/
10+
11+
class upd_0001 extends installer_patch_update {
12+
13+
public function onBeforeSQL() {
14+
// Do something
15+
}
16+
public function onAfterSQL() {
17+
// Do something
18+
}
19+
}
20+
21+
?>

install/update.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
error_reporting(E_ALL|E_STRICT);
3636

37+
define('INSTALLER_RUN', true);
38+
3739
//** The banner on the command line
3840
echo "\n\n".str_repeat('-',80)."\n";
3941
echo " _____ ___________ _____ __ _ ____

0 commit comments

Comments
 (0)