MDL-24343 core: Deprecate unzip_file

This commit is contained in:
Andrew Nicols
2016-08-03 09:05:55 +08:00
parent 56b9e796af
commit 2c2f4f17c3
11 changed files with 202 additions and 31 deletions
+19 -16
View File
@@ -268,15 +268,13 @@ class component_installer {
* compare md5 values, download, unzip, install and regenerate
* local md5 file
*
* @global object
* @uses COMPONENT_ERROR
* @uses COMPONENT_UPTODATE
* @uses COMPONENT_ERROR
* @uses COMPONENT_INSTALLED
* @return int COMPONENT_(ERROR | UPTODATE | INSTALLED)
*/
function install() {
public function install() {
global $CFG;
/// Check requisites are passed
@@ -330,25 +328,30 @@ class component_installer {
$this->errorstring='downloadedfilecheckfailed';
return COMPONENT_ERROR;
}
/// Move current revision to a safe place
$destinationdir = $CFG->dataroot.'/'.$this->destpath;
$destinationcomponent = $destinationdir.'/'.$this->componentname;
@remove_dir($destinationcomponent.'_old'); // Deleting a possible old version.
// Move current revision to a safe place.
$destinationdir = $CFG->dataroot . '/' . $this->destpath;
$destinationcomponent = $destinationdir . '/' . $this->componentname;
$destinationcomponentold = $destinationcomponent . '_old';
@remove_dir($destinationcomponentold); // Deleting a possible old version.
// Moving to a safe place.
@rename($destinationcomponent, $destinationcomponent.'_old');
@rename($destinationcomponent, $destinationcomponentold);
/// Unzip new version
if (!unzip_file($zipfile, $destinationdir, false)) {
/// Error so, go back to the older
// Unzip new version.
$packer = get_file_packer('application/zip');
$unzipsuccess = $packer->extract_to_pathname($zipfile, $destinationdir, null, null, true);
if (!$unzipsuccess) {
@remove_dir($destinationcomponent);
@rename ($destinationcomponent.'_old', $destinationcomponent);
$this->errorstring='cannotunzipfile';
@rename($destinationcomponentold, $destinationcomponent);
$this->errorstring = 'cannotunzipfile';
return COMPONENT_ERROR;
}
/// Delete old component version
@remove_dir($destinationcomponent.'_old');
/// Create local md5
// Delete old component version.
@remove_dir($destinationcomponentold);
// Create local md5.
if ($file = fopen($destinationcomponent.'/'.$this->componentname.'.md5', 'w')) {
if (!fwrite($file, $new_md5)) {
fclose($file);