Skip to content

Commit

Permalink
MDL-12698, MDL-12569 - componentlib & langimport improvements and fix…
Browse files Browse the repository at this point in the history
…es; merged from MOODLE_19_STABLE
  • Loading branch information
skodak committed Dec 30, 2007
1 parent 5f8bdc1 commit a7d43f0
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 198 deletions.
2 changes: 1 addition & 1 deletion admin/environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
$status = $cd->install(); //returns ERROR | UPTODATE | INSTALLED
switch ($status) {
case ERROR:
if ($cd->get_error() == 'remotedownloadnotallowed') {
if ($cd->get_error() == 'remotedownloaderror') {
$a = new stdClass();
$a->url = 'http://download.moodle.org/environment/environment.zip';
$a->dest= $CFG->dataroot.'/';
Expand Down
325 changes: 165 additions & 160 deletions admin/langimport.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion install.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@
$status = $cd->install(); //returns ERROR | UPTODATE | INSTALLED
switch ($status) {
case ERROR:
if ($cd->get_error() == 'remotedownloadnotallowed') {
if ($cd->get_error() == 'remotedownloaderror') {
$a = new stdClass();
$a->url = 'http://download.moodle.org/lang16/'.$pack.'.zip';
$a->dest= $CFG->dataroot.'/lang';
Expand Down
1 change: 1 addition & 0 deletions install/stringnames.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ postgres7
previous
qtyperqpwillberemoved
qtyperqpwillberemovedanyway
remotedownloaderror
remotedownloadnotallowed
report
restricted
Expand Down
6 changes: 4 additions & 2 deletions lang/en_utf8/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,12 @@
$string['langlist'] = 'Languages on language menu';
$string['langmenu'] = 'Display language menu';
$string['langnoeditenglish'] = 'Can\'t overwrite the base english language pack. Please switch lang directory to make local changes';
$string['langpackinstalled'] = 'Language pack $a was successfully installed';
$string['langpackmaintaining'] = 'Language pack maintaining';
$string['langpackremoved'] = 'Language pack was uninstalled';
$string['langpacks'] = 'Language packs';
$string['langpackupdated'] = 'Language pack $a was successfully installed';
$string['langpackupdated'] = 'Language pack $a was successfully updated';
$string['langpackupdateskipped'] = 'Update of $a language pack skipped';
$string['langpackwillbeupdated'] = 'Note for translators: During the upgrade, Moodle will try to update your language pack. Your modifications in non-local language folders will be overwritten.';
$string['langrmyourself'] = 'To prevent data loss, lang.php is not able to overwrite existing file with empty content. Please, remove the file manually in order to get rid of it.';
$string['languagesettings'] = 'Language settings';
Expand Down Expand Up @@ -651,7 +653,7 @@
$string['unsupported'] = 'Unsupported';
$string['updateaccounts'] = 'Update existing accounts';
$string['updatecomponent'] = 'Update Component';
$string['updatelangs'] = 'Update all local language packs';
$string['updatelangs'] = 'Update all installed language packs';
$string['updatetimezones'] = 'Update timezones';
$string['upgradeforumread'] = 'A new feature has been added in Moodle 1.5 to track read/unread forum posts.<br />To use this functionality you need to <a href=\"$a\">update your tables</a>.';
$string['upgradeforumreadinfo'] = 'A new feature has been added in Moodle 1.5 to track read/unread forum posts. To use this functionality you need to update your tables with all the tracking information for existing posts. Depending on the size of your site this can take a long time (hours) and can be quite taxing on the database, so it\'s best to do it during a quiet period. However, your site will continue functioning during this upgrade and users won\'t be affected. Once you start this process you should let it finish (keep your browser window open). However, if you stop the process by closing the window: don\'t worry, you can start over.<br /><br />Do you want to start the upgrading process now?';
Expand Down
1 change: 1 addition & 0 deletions lang/en_utf8/error.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
$string['pleasereport'] = 'If you have time, please let us know what you were trying to do when the error occurred:';
$string['pluginrequirementsnotmet'] = 'Plugin \"$a->pluginname\" ($a->pluginversion) could not be installed. It requires a newer version of Moodle (currently you are using $a->currentmoodle, you need $a->requiremoodle).';
$string['processingstops'] = 'Processing stops here. Remaining records ignored.';
$string['remotedownloaderror'] = 'Download of component to your server failed, please verify proxy settings, PHP cURL extension is highly recommended.<br /><br />You must download the <a href=\"$a->url\">$a->url</a> file manually, copy it to \"$a->dest\" in your server and unzip it there.';
$string['remotedownloadnotallowed'] = 'Download of components to your server isn\'t allowed (allow_url_fopen is disabled).<br /><br />You must download the <a href=\"$a->url\">$a->url</a> file manually, copy it to \"$a->dest\" in your server and unzip it there.';
$string['restricteduser'] = 'Sorry, but your current account \"$a\" is restricted from doing that.';
$string['scheduledbackupsdisabled'] = 'Scheduled backups have been disabled by the server admin';
Expand Down
63 changes: 30 additions & 33 deletions lib/componentlib.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.com //
// //
// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
// //
// This program is free software; you can redistribute it and/or modify //
Expand All @@ -27,19 +27,19 @@
// This library includes all the necessary stuff to use the one-click
// download and install feature of Moodle, used to keep updated some
// items like languages, pear, enviroment... i.e, components.
//
// It has been developed harcoding some important limits that are
//
// It has been developed harcoding some important limits that are
// explained below:
// - It only can check, download and install items under moodledata.
// - Every downloadeable item must be one zip file.
// - The zip file root content must be 1 directory, i.e, everything
// is stored under 1 directory.
// - Zip file name and root directory must have the same name (but
// - Zip file name and root directory must have the same name (but
// the .zip extension, of course).
// - Every .zip file must be defined in one .md5 file that will be
// stored in the same remote directory than the .zip file.
// - The name of such .md5 file is free, although it's recommended
// to use the same name than the .zip (that's the default
// to use the same name than the .zip (that's the default
// assumption if no specified).
// - Every remote .md5 file will be a comma separated (CVS) file where each
// line will follow this format:
Expand All @@ -52,7 +52,6 @@
// - Will contain the md5 od the latest installed component
// With all these details present, the process will perform this tasks:
// - Perform security checks. Only admins are allowed to use this for now.
// - Perform server checks. fopen must allow to open remote URLs.
// - Read the .md5 file from source (1).
// - Extract the correct line for the .zip being requested.
// - Compare it with the local .md5 file (2).
Expand All @@ -68,21 +67,20 @@
// - If different:
// - ERROR. Old package won't be modified. We shouldn't
// reach here ever.
// - If fopen is not available, a message text about how to do
// the process manually (remotedownloadnotallowed) must be
// built to explain it.
// - If component download is not possible, a message text about how to do
// the process manually (remotedownloaderror) must be displayed to explain it.
//
// General Usage:
//
// To install one component:
//
// require_once($CFG->libdir.'/componentlib.class.php');
// if ($cd = new component_installer('http://download.moodle.org', 'lang16',
// if ($cd = new component_installer('http://download.moodle.org', 'lang16',
// 'es_utf8.zip', 'languages.md5', 'lang')) {
// $status = $cd->install(); //returns ERROR | UPTODATE | INSTALLED
// switch ($status) {
// case ERROR:
// if ($cd->get_error() == 'remotedownloadnotallowed') {
// case ERROR:
// if ($cd->get_error() == 'remotedownloaderror') {
// $a = new stdClass();
// $a->url = 'http://download.moodle.org/lang16/es_utf8.zip';
// $a->dest= $CFG->dataroot.'/lang';
Expand Down Expand Up @@ -144,7 +142,7 @@
class component_installer {

var $sourcebase; /// Full http URL, base for downloadable items
var $zippath; /// Relative path (from sourcebase) where the
var $zippath; /// Relative path (from sourcebase) where the
/// downloadeable item resides.
var $zipfilename; /// Name of the .zip file to be downloaded
var $md5filename; /// Name of the .md5 file to be read
Expand All @@ -166,12 +164,12 @@ class component_installer {
* without performing any check at all.
*
* @param string Full http URL, base for downloadeable items
* @param string Relative path (from sourcebase) where the
* @param string Relative path (from sourcebase) where the
* downloadeable item resides
* @param string Name of the .zip file to be downloaded
* @param string Name of the .md5 file to be read (default '' = same
* @param string Name of the .md5 file to be read (default '' = same
* than zipfilename)
* @param string Relative path (from moodledata) where the .zip file will
* @param string Relative path (from moodledata) where the .zip file will
* be expanded (default='' = moodledataitself)
* @return object
*/
Expand All @@ -193,8 +191,7 @@ function component_installer ($sourcebase, $zippath, $zipfilename, $md5filename=

/**
* This function will check if everything is properly set to begin
* one installation. It'll check for fopen wrappers enabled and
* admin privileges. Also, it will check for required settings
* one installation. Also, it will check for required settings
* and will fill everything as needed.
*
* @return boolean true/false (plus detailed error in errorstring)
Expand All @@ -204,11 +201,6 @@ function check_requisites() {

$this->requisitesok = false;

/// Check for fopen remote enabled
if (!ini_get('allow_url_fopen')) {
$this->errorstring='remotedownloadnotallowed';
return false;
}
/// Check that everything we need is present
if (empty($this->sourcebase) || empty($this->zippath) || empty($this->zipfilename)) {
$this->errorstring='missingrequiredfield';
Expand All @@ -231,7 +223,7 @@ function check_requisites() {
return false;
}
}
/// Calculate the componentnamea
/// Calculate the componentname
$pos = stripos($this->zipfilename, '.zip');
$this->componentname = substr($this->zipfilename, 0, $pos);
/// Calculate md5filename if it's empty
Expand Down Expand Up @@ -304,7 +296,7 @@ function install() {
$destinationdir = $CFG->dataroot.'/'.$this->destpath;
$destinationcomponent = $destinationdir.'/'.$this->componentname;
@remove_dir($destinationcomponent.'_old'); //Deleting possible old components before
@rename ($destinationcomponent, $destinationcomponent.'_old'); //Moving to a safe place
@rename ($destinationcomponent, $destinationcomponent.'_old'); //Moving to a safe place
/// Unzip new version
if (!unzip_file($zipfile, $destinationdir, false)) {
/// Error so, go back to the older
Expand Down Expand Up @@ -359,7 +351,7 @@ function need_upgrade() {
}
}

/**
/**
* This function will change the zip file to install on the fly
* to allow the class to process different components of the
* same md5 file without intantiating more objects.
Expand Down Expand Up @@ -416,7 +408,9 @@ function get_component_md5() {
}
/// Get all components of md5 file
if (!$comp_arr = $this->get_all_components_md5()) {
$this->errorstring='cannotdownloadcomponents';
if (empty($this->errorstring)) {
$this->errorstring='cannotdownloadcomponents';
}
return false;
}
/// Search for the componentname component
Expand All @@ -436,8 +430,8 @@ function get_component_md5() {
return $component[1];
}

/**
* This function allows you to retrieve the complete array of components found in
/**
* This function allows you to retrieve the complete array of components found in
* the md5filename
*
* @return array array of components in md5 file or false if error
Expand Down Expand Up @@ -493,12 +487,15 @@ function get_all_components_md5() {
$this->cachedmd5components[$source] = $comp_arr;
} else {
/// Return error
$this->errorstring='cannotdownloadcomponents';
$this->errorstring='remotedownloaderror';
return false;
}
}
/// If there is no commponents, error
if (empty($comp_arr)) {
/// If there is no commponents or erros found, error
if (!empty($this->errorstring)) {
return false;

} else if (empty($comp_arr)) {
$this->errorstring='cannotdownloadcomponents';
return false;
}
Expand All @@ -515,7 +512,7 @@ function get_error() {
}

/** This function returns the extramd5 field (optional in md5 file)
*
*
* @return string the extramd5 field
*/
function get_extra_md5_field() {
Expand Down
2 changes: 1 addition & 1 deletion lib/languages.md5
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ be_utf8,f38e8e0b312376eec708fd9f95aa04fb,Беларуская
bg_utf8,676f4a9b93800c1cacbf9ca4ee5010b2,Български
bs_utf8,9ad1de9a6ab3f54f59eeab8d7ce867d1,Bosanski
ca_utf8,dbe5f8d6a111839a5d89533a5ce37815,Català
cs_utf8,87ae11d3bac8effd71a06b43da80f401,Cestina
cs_utf8,87ae11d3bac8effd71a06b43da80f401,Čeština
da_utf8,066302a39241bfd7db7b3dfa0e53d658,Dansk
de_du_utf8,c5cc95e33762bb1b4faba54824b383f6,Deutsch - Du
de_utf8,d04fcaf901ae31a65c273211650c7239,Deutsch
Expand Down

0 comments on commit a7d43f0

Please sign in to comment.