From f85236dc76249fc1cd0786b03e933e1f1564f5d6 Mon Sep 17 00:00:00 2001 From: stronk7 Date: Mon, 31 Dec 2007 01:07:49 +0000 Subject: [PATCH] Change some constants to avoid name collisions. MDL-12698 ; Merged from MOODLE_19_STABLE --- admin/langimport.php | 16 +++++----- install.php | 8 ++--- lib/adminlib.php | 4 +-- lib/componentlib.class.php | 60 +++++++++++++++++++------------------- 4 files changed, 44 insertions(+), 44 deletions(-) diff --git a/admin/langimport.php b/admin/langimport.php index 4c0b084d09..669664ffd5 100755 --- a/admin/langimport.php +++ b/admin/langimport.php @@ -47,10 +47,10 @@ if ($cd = new component_installer('http://download.moodle.org', 'lang16', $pack.'.zip', 'languages.md5', 'lang')) { - $status = $cd->install(); //returns ERROR | UPTODATE | INSTALLED + $status = $cd->install(); //returns COMPONENT_(ERROR | UPTODATE | INSTALLED) switch ($status) { - case ERROR: + case COMPONENT_ERROR: if ($cd->get_error() == 'remotedownloaderror') { $a = new object(); $a->url = 'http://download.moodle.org/lang16/'.$pack.'.zip'; @@ -61,11 +61,11 @@ } break; - case INSTALLED: + case COMPONENT_INSTALLED: $notice_ok[] = get_string('langpackinstalled','admin',$pack); break; - case UPTODATE: + case COMPONENT_UPTODATE: break; } @@ -180,10 +180,10 @@ if ($cd = new component_installer('http://download.moodle.org', 'lang16', $pack.'.zip', 'languages.md5', 'lang')) { - $status = $cd->install(); //returns ERROR | UPTODATE | INSTALLED + $status = $cd->install(); //returns COMPONENT_(ERROR | UPTODATE | INSTALLED) switch ($status) { - case ERROR: + case COMPONENT_ERROR: if ($cd->get_error() == 'remotedownloaderror') { $a = new stdClass(); $a->url = 'http://download.moodle.org/lang16/'.$pack.'.zip'; @@ -193,10 +193,10 @@ error(get_string($cd->get_error(), 'error')); // not probable } break; - case UPTODATE: + case COMPONENT_UPTODATE: //Print error string or whatever you want to do break; - case INSTALLED: + case COMPONENT_INSTALLED: $notice_ok[] = get_string('langpackupdated', 'admin', $pack); $updated = true; //Print/do whatever you want diff --git a/install.php b/install.php index 18e8156ee3..8983a827e1 100644 --- a/install.php +++ b/install.php @@ -467,9 +467,9 @@ if ($INSTALL['stage'] == DOWNLOADLANG && $INSTALL['downloadlangpack']) { /// Download and install component if (($cd = new component_installer('http://download.moodle.org', 'lang16', $INSTALL['language'].'.zip', 'languages.md5', 'lang')) && empty($errormsg)) { - $status = $cd->install(); //returns ERROR | UPTODATE | INSTALLED + $status = $cd->install(); //returns COMPONENT_(ERROR | UPTODATE | INSTALLED) switch ($status) { - case ERROR: + case COMPONENT_ERROR: if ($cd->get_error() == 'remotedownloaderror') { $a = new stdClass(); $a->url = 'http://download.moodle.org/lang16/'.$pack.'.zip'; @@ -479,8 +479,8 @@ if ($INSTALL['stage'] == DOWNLOADLANG && $INSTALL['downloadlangpack']) { $downloaderror = get_string($cd->get_error(), 'error'); } break; - case UPTODATE: - case INSTALLED: + case COMPONENT_UPTODATE: + case COMPONENT_INSTALLED: $downloadsuccess = true; break; default: diff --git a/lib/adminlib.php b/lib/adminlib.php index bcd2189888..29943d1753 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -4367,9 +4367,9 @@ function upgrade_language_pack($lang='') { require_once($CFG->libdir.'/componentlib.class.php'); if ($cd = new component_installer('http://download.moodle.org', 'lang16', $lang.'.zip', 'languages.md5', 'lang')) { - $status = $cd->install(); //returns ERROR | UPTODATE | INSTALLED + $status = $cd->install(); //returns COMPONENT_(ERROR | UPTODATE | INSTALLED) - if ($status == INSTALLED) { + if ($status == COMPONENT_INSTALLED) { debugging('Downloading successful: '.$lang); @unlink($CFG->dataroot.'/cache/languages'); return true; diff --git a/lib/componentlib.class.php b/lib/componentlib.class.php index 1130393d6e..a394d7786c 100644 --- a/lib/componentlib.class.php +++ b/lib/componentlib.class.php @@ -77,9 +77,9 @@ // require_once($CFG->libdir.'/componentlib.class.php'); // if ($cd = new component_installer('http://download.moodle.org', 'lang16', // 'es_utf8.zip', 'languages.md5', 'lang')) { -// $status = $cd->install(); //returns ERROR | UPTODATE | INSTALLED +// $status = $cd->install(); //returns COMPONENT_(ERROR | UPTODATE | INSTALLED) // switch ($status) { -// case ERROR: +// case COMPONENT_ERROR: // if ($cd->get_error() == 'remotedownloaderror') { // $a = new stdClass(); // $a->url = 'http://download.moodle.org/lang16/es_utf8.zip'; @@ -89,10 +89,10 @@ // error(get_string($cd->get_error(), 'error')); // } // break; -// case UPTODATE: +// case COMPONENT_UPTODATE: // //Print error string or whatever you want to do // break; -// case INSTALLED: +// case COMPONENT_INSTALLED: // //Print/do whatever you want // break; // default: @@ -112,7 +112,7 @@ // // To check if current component needs to be updated // -// $status = $cd->need_upgrade(); //returns ERROR | UPTODATE | NEEDUPDATE +// $status = $cd->need_upgrade(); //returns COMPONENT_(ERROR | UPTODATE | NEEDUPDATE) // // To get the 3rd field of the md5 file (optional) // @@ -126,10 +126,10 @@ global $CFG; require_once($CFG->libdir.'/filelib.php'); // Some needed constants -define('ERROR', 0); -define('UPTODATE', 1); -define('NEEDUPDATE', 2); -define('INSTALLED', 3); +define('COMPONENT_ERROR', 0); +define('COMPONENT_UPTODATE', 1); +define('COMPONENT_NEEDUPDATE', 2); +define('COMPONENT_INSTALLED', 3); /** * This class is used to check, download and install items from @@ -240,7 +240,7 @@ class component_installer { * compare md5 values, download, unzip, install and regenerate * local md5 file * - * @return int ERROR | UPTODATE | INSTALLED + * @return int COMPONENT_(ERROR | UPTODATE | INSTALLED) */ function install() { @@ -248,19 +248,19 @@ class component_installer { /// Check requisites are passed if (!$this->requisitesok) { - return ERROR; + return COMPONENT_ERROR; } /// Confirm we need upgrade - if ($this->need_upgrade() === ERROR) { - return ERROR; - } else if ($this->need_upgrade() === UPTODATE) { + if ($this->need_upgrade() === COMPONENT_ERROR) { + return COMPONENT_ERROR; + } else if ($this->need_upgrade() === COMPONENT_UPTODATE) { $this->errorstring='componentisuptodate'; - return UPTODATE; + return COMPONENT_UPTODATE; } /// Create temp directory if necesary if (!make_upload_directory('temp', false)) { $this->errorstring='cannotcreatetempdir'; - return ERROR; + return COMPONENT_ERROR; } /// Download zip file and save it to temp $source = $this->sourcebase.'/'.$this->zippath.'/'.$this->zipfilename; @@ -271,26 +271,26 @@ class component_installer { if (!fwrite($file, $contents)) { fclose($file); $this->errorstring='cannotsavezipfile'; - return ERROR; + return COMPONENT_ERROR; } } else { $this->errorstring='cannotsavezipfile'; - return ERROR; + return COMPONENT_ERROR; } fclose($file); } else { $this->errorstring='cannotdownloadzipfile'; - return ERROR; + return COMPONENT_ERROR; } /// Calculate its md5 $new_md5 = md5($contents); /// Compare it with the remote md5 to check if we have the correct zip file if (!$remote_md5 = $this->get_component_md5()) { - return ERROR; + return COMPONENT_ERROR; } if ($new_md5 != $remote_md5) { $this->errorstring='downloadedfilecheckfailed'; - return ERROR; + return COMPONENT_ERROR; } /// Move current revision to a safe place $destinationdir = $CFG->dataroot.'/'.$this->destpath; @@ -303,7 +303,7 @@ class component_installer { @remove_dir($destinationcomponent); @rename ($destinationcomponent.'_old', $destinationcomponent); $this->errorstring='cannotunzipfile'; - return ERROR; + return COMPONENT_ERROR; } /// Delete old component version @remove_dir($destinationcomponent.'_old'); @@ -312,42 +312,42 @@ class component_installer { if (!fwrite($file, $new_md5)) { fclose($file); $this->errorstring='cannotsavemd5file'; - return ERROR; + return COMPONENT_ERROR; } } else { $this->errorstring='cannotsavemd5file'; - return ERROR; + return COMPONENT_ERROR; } fclose($file); /// Delete temp zip file @unlink($zipfile); - return INSTALLED; + return COMPONENT_INSTALLED; } /** * This function will detect if remote component needs to be installed * because it's different from the local one * - * @return int ERROR | UPTODATE | NEEDUPDATE + * @return int COMPONENT_(ERROR | UPTODATE | NEEDUPDATE) */ function need_upgrade() { /// Check requisites are passed if (!$this->requisitesok) { - return ERROR; + return COMPONENT_ERROR; } /// Get local md5 $local_md5 = $this->get_local_md5(); /// Get remote md5 if (!$remote_md5 = $this->get_component_md5()) { - return ERROR; + return COMPONENT_ERROR; } /// Return result if ($local_md5 == $remote_md5) { - return UPTODATE; + return COMPONENT_UPTODATE; } else { - return NEEDUPDATE; + return COMPONENT_NEEDUPDATE; } } -- 2.39.5