|
27 | 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | 28 | */ |
29 | 29 |
|
| 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 |
30 | 39 | function prepareDBDump() { |
31 | 40 | global $conf; |
32 | 41 |
|
@@ -151,16 +160,39 @@ function updateDbAndIni() { |
151 | 160 | $found = true; |
152 | 161 | while($found == true) { |
153 | 162 | $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 | + |
156 | 181 | //* Load patch file into database |
157 | 182 | 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); |
159 | 184 | } 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(); |
161 | 192 | } |
162 | | - swriteln($inst->lng('Loading SQL patch file').': '.$patch_filename); |
| 193 | + |
163 | 194 | $current_db_version = $next_db_version; |
| 195 | + if(isset($php_patch)) unset($php_patch); |
164 | 196 | } else { |
165 | 197 | $found = false; |
166 | 198 | } |
@@ -332,4 +364,6 @@ function updateDbAndIni() { |
332 | 364 | unset($new_ini); |
333 | 365 | } |
334 | 366 |
|
| 367 | + |
| 368 | + |
335 | 369 | ?> |
0 commit comments