Skip to content

Commit

Permalink
Merge branch 'save_config_to_config_plugins' of https://github.com/eb…
Browse files Browse the repository at this point in the history
…erhardt/moodle-mod_etherpadlite into eberhardt-save_config_to_config_plugins
  • Loading branch information
tjwelde committed Jan 15, 2014
2 parents 86fe86e + 7cbefc8 commit 8d8af84
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 135 deletions.
35 changes: 19 additions & 16 deletions backup/moodle2/backup_etherpadlite_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* @package mod
* @subpackage etherpadlite
Expand All @@ -26,46 +26,49 @@

/**
* Define the complete podcaster structure for backup, with file and id annotations
*/
*/
class backup_etherpadlite_activity_structure_step extends backup_activity_structure_step {

protected function define_structure() {
global $CFG, $DB;
$instance = new EtherpadLiteClient($CFG->etherpadlite_apikey,$CFG->etherpadlite_url.'api');

global $DB;

$config = get_config("etherpadlite");

$instance = new EtherpadLiteClient($config->apikey,$config->url.'api');

// To know if we are including userinfo
$userinfo = $this->get_setting_value('userinfo');

// Define each element separated
$eplite = new backup_nested_element('etherpadlite', array('id'), array(
'name', 'intro', 'introformat', 'guestsallowed', 'timecreated', 'timemodified'));

$content = new backup_nested_element('content', null, array('html', 'text', ));

// Build the tree
$eplite->add_child($content);

// Define sources
$eplite->set_source_table('etherpadlite', array('id' => backup::VAR_ACTIVITYID));

// All the rest of elements only happen if we are including user info
if ($userinfo) {
// The HTML content of the pad
$modid = $this->task->get_activityid();
$padID = $DB->get_field('etherpadlite', 'uri', array('id' => $modid));
$html = $instance->getHTML($padID);
$text = $instance->getText($padID);

$content->set_source_array(array((object)array('html'=>$html->html, 'text'=>$text->text)));
}

// Define id annotations
// We have none

// Define file annotations

// Return the root element (etherpadlite), wrapped into standard activity structure
return $this->prepare_activity_structure($eplite);

}
}
60 changes: 31 additions & 29 deletions backup/moodle2/restore_etherpadlite_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* @package mod
* @subpackage etherpadlite
Expand All @@ -29,34 +29,35 @@
* Structure step to restore one etherpadlite activity
*/
class restore_etherpadlite_activity_structure_step extends restore_activity_structure_step {

protected function define_structure() {

$paths = array();
$userinfo = $this->get_setting_value('userinfo');

$paths[] = new restore_path_element('etherpadlite', '/activity/etherpadlite');

if($userinfo) {
$paths[] = new restore_path_element('etherpadlite_content', '/activity/etherpadlite/content');
}

// Return the paths wrapped into standard activity structure
return $this->prepare_activity_structure($paths);
}

protected function process_etherpadlite($data) {
global $DB, $CFG;
global $DB;
$config = get_config("etherpadlite");
$data = (object)$data;
$oldid = $data->id;
$data->course = $this->get_courseid();

// php.ini separator.output auf '&' setzen
$separator = ini_get('arg_separator.output');
ini_set('arg_separator.output', '&');
$instance = new EtherpadLiteClient($CFG->etherpadlite_apikey,$CFG->etherpadlite_url.'api');

$instance = new EtherpadLiteClient($config->apikey,$config->url.'api');

try {
$createGroup = $instance->createGroup();
$groupID = $createGroup->groupID;
Expand All @@ -65,61 +66,62 @@ protected function process_etherpadlite($data) {
// the group already exists or something else went wrong
echo "\n\ncreateGroup Failed with message ". $e->getMessage();
}

try {
$newpad = $instance->createGroupPad($groupID, $CFG->etherpadlite_padname);
$newpad = $instance->createGroupPad($groupID, $config->padname);
$padID = $newpad->padID;
//echo "Created new pad with padID: $padID\n\n";
} catch (Exception $e) {
// the pad already exists or something else went wrong
echo "\n\ncreateGroupPad Failed with message ". $e->getMessage();
}

// seperator.output wieder zur�cksetzen
ini_set('arg_separator.output', $separator);

$data->uri = $padID;

$data->timecreated = $this->apply_date_offset($data->timecreated);
$data->timemodified = $this->apply_date_offset($data->timemodified);

// insert the etherpadlite record
$newitemid = $DB->insert_record('etherpadlite', $data);
// immediately after inserting "activity" record, call this
$this->apply_activity_instance($newitemid);
}

protected function process_etherpadlite_content($data) {
global $DB, $CFG;
global $DB;
$config = get_config("etherpadlite");
$data = (object)$data;
$instance = new EtherpadLiteClient($CFG->etherpadlite_apikey,$CFG->etherpadlite_url.'api');
$instance = new EtherpadLiteClient($config->apikey,$config->url.'api');

$newid = $this->get_new_parentid('etherpadlite');
$etherpadlite = $DB->get_record('etherpadlite', array('id'=>$newid));
$padID = $etherpadlite->uri;


// php.ini separator.output auf '&' setzen
$separator = ini_get('arg_separator.output');
ini_set('arg_separator.output', '&');
$instance = new EtherpadLiteClient($CFG->etherpadlite_apikey,$CFG->etherpadlite_url.'api');

$instance = new EtherpadLiteClient($config->apikey,$config->url.'api');

try {
$instance->setHTML($padID, '<html>'.$data->html.'</html>');
} catch (Exception $e) {
// something went wrong
echo "\n\nsetHTML Failed with message ". $e->getMessage();
}

// seperator.output wieder zur�cksetzen
ini_set('arg_separator.output', $separator);
}

protected function after_execute() {
// Add etherpadlite related files, no need to match by itemname (just internally handled context)
global $DB;
//$this->add_related_files('mod_etherpadlite', 'intro', null);

}
}
20 changes: 18 additions & 2 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
function xmldb_etherpadlite_upgrade($oldversion=0) {

global $CFG, $THEME, $DB;

$dbman = $DB->get_manager(); // loads ddl manager and xmldb classes

$result = true;

/// And upgrade begins here. For each one, you'll need one
Expand All @@ -46,6 +46,22 @@ function xmldb_etherpadlite_upgrade($oldversion=0) {
/// $result = result of "/lib/ddllib.php" function calls
/// }

if ($oldversion < 2013042901)
{
set_config("url", $CFG->etherpadlite_url, "etherpadlite");
set_config("apikey", $CFG->etherpadlite_apikey, "etherpadlite");
set_config("padname", $CFG->etherpadlite_padname, "etherpadlite");
set_config("cookiedomain", $CFG->etherpadlite_cookiedomain, "etherpadlite");
set_config("cookietime", $CFG->etherpadlite_cookietime, "etherpadlite");
set_config("ssl", $CFG->etherpadlite_ssl, "etherpadlite");
set_config("check_ssl", $CFG->etherpadlite_check_ssl, "etherpadlite");
set_config("adminguests", $CFG->etherpadlite_adminguests, "etherpadlite");

$DB->delete_records_select("config", "name LIKE 'etherpadlite_%'");

upgrade_plugin_savepoint(true, 2013042901, "mod", "etherpadlite");
}

return $result;
}

Expand Down
Loading

0 comments on commit 8d8af84

Please sign in to comment.