Skip to content

Commit

Permalink
Change some constants to avoid name collisions. MDL-12698
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Dec 31, 2007
1 parent 5738a67 commit 6dbe040
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 44 deletions.
16 changes: 8 additions & 8 deletions admin/langimport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -61,11 +61,11 @@
}
break;

case INSTALLED:
case COMPONENT_INSTALLED:
$notice_ok[] = get_string('langpackinstalled','admin',$pack);
break;

case UPTODATE:
case COMPONENT_UPTODATE:
break;

}
Expand Down Expand Up @@ -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';
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions install.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,9 @@
/// 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';
Expand All @@ -479,8 +479,8 @@
$downloaderror = get_string($cd->get_error(), 'error');
}
break;
case UPTODATE:
case INSTALLED:
case COMPONENT_UPTODATE:
case COMPONENT_INSTALLED:
$downloadsuccess = true;
break;
default:
Expand Down
4 changes: 2 additions & 2 deletions lib/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
60 changes: 30 additions & 30 deletions lib/componentlib.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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:
Expand All @@ -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)
//
Expand All @@ -126,10 +126,10 @@
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
Expand Down Expand Up @@ -240,27 +240,27 @@ function check_requisites() {
* compare md5 values, download, unzip, install and regenerate
* local md5 file
*
* @return int ERROR | UPTODATE | INSTALLED
* @return int COMPONENT_(ERROR | UPTODATE | INSTALLED)
*/
function install() {

global $CFG;

/// 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;
Expand All @@ -271,26 +271,26 @@ function install() {
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;
Expand All @@ -303,7 +303,7 @@ function install() {
@remove_dir($destinationcomponent);
@rename ($destinationcomponent.'_old', $destinationcomponent);
$this->errorstring='cannotunzipfile';
return ERROR;
return COMPONENT_ERROR;
}
/// Delete old component version
@remove_dir($destinationcomponent.'_old');
Expand All @@ -312,42 +312,42 @@ function install() {
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;
}
}

Expand Down

0 comments on commit 6dbe040

Please sign in to comment.