public function set_value($value)
 {
     global $CFG;
     $localhostwwwroot = backup_plan_dbops::get_mnet_localhost_wwwroot();
     // If user wwwroot matches mnet local host one or if
     // there isn't associated wwwroot, skip sending it to file
     if ($localhostwwwroot == $value || empty($value)) {
         // Do nothing
     } else {
         parent::set_value($value);
     }
 }
Пример #2
0
 /**
  * Set the value for the final element, encoding it as utf-8/xml safe base64.
  *
  * @param string $value Original value coming from backup step source, usually db.
  */
 public function set_value($value)
 {
     parent::set_value(base64_encode($value));
 }
Пример #3
0
 public function set_value($value)
 {
     // Get grandparent name
     $gpname = $this->get_grandparent()->get_name();
     // Get parent name
     $pname = $this->get_parent()->get_name();
     // Get my name
     $myname = $this->get_name();
     // Define class and function name
     $classname = 'mock_' . $gpname . '_' . $pname . '_interceptor';
     $methodname = 'intercept_' . $pname . '_' . $myname;
     // Invoke the interception method
     $result = call_user_func(array($classname, $methodname), $value);
     // Finally set it
     parent::set_value($result);
 }
Пример #4
0
 /**
  * Backup structures wrong tests (trying to do things the wrong way)
  */
 function test_backup_structure_wrong()
 {
     // Instantiate the backup processor
     $processor = new backup_structure_processor(new xml_writer(new memory_xml_output()));
     $this->assertTrue($processor instanceof base_processor);
     // Set one var twice
     $processor->set_var('onenewvariable', 999);
     try {
         $processor->set_var('onenewvariable', 999);
         $this->assertTrue(false, 'backup_processor_exception expected');
     } catch (exception $e) {
         $this->assertTrue($e instanceof backup_processor_exception);
         $this->assertEquals($e->errorcode, 'processorvariablealreadyset');
         $this->assertEquals($e->a, 'onenewvariable');
     }
     // Get non-existing var
     try {
         $var = $processor->get_var('nonexistingvar');
         $this->assertTrue(false, 'backup_processor_exception expected');
     } catch (exception $e) {
         $this->assertTrue($e instanceof backup_processor_exception);
         $this->assertEquals($e->errorcode, 'processorvariablenotfound');
         $this->assertEquals($e->a, 'nonexistingvar');
     }
     // Create nested element and try ro get its parent id (doesn't exisit => exception)
     $ne = new backup_nested_element('test', 'one', 'two', 'three');
     try {
         $ne->set_source_table('forum', array('id' => backup::VAR_PARENTID));
         $ne->process($processor);
         $this->assertTrue(false, 'base_element_struct_exception expected');
     } catch (exception $e) {
         $this->assertTrue($e instanceof base_element_struct_exception);
         $this->assertEquals($e->errorcode, 'cannotfindparentidforelement');
     }
     // Try to process one nested/final/attribute elements without processor
     $ne = new backup_nested_element('test', 'one', 'two', 'three');
     try {
         $ne->process(new stdclass());
         $this->assertTrue(false, 'base_element_struct_exception expected');
     } catch (exception $e) {
         $this->assertTrue($e instanceof base_element_struct_exception);
         $this->assertEquals($e->errorcode, 'incorrect_processor');
     }
     $fe = new backup_final_element('test');
     try {
         $fe->process(new stdclass());
         $this->assertTrue(false, 'base_element_struct_exception expected');
     } catch (exception $e) {
         $this->assertTrue($e instanceof base_element_struct_exception);
         $this->assertEquals($e->errorcode, 'incorrect_processor');
     }
     $at = new backup_attribute('test');
     try {
         $at->process(new stdclass());
         $this->assertTrue(false, 'base_element_struct_exception expected');
     } catch (exception $e) {
         $this->assertTrue($e instanceof base_element_struct_exception);
         $this->assertEquals($e->errorcode, 'incorrect_processor');
     }
     // Try to put an incorrect alias
     $ne = new backup_nested_element('test', 'one', 'two', 'three');
     try {
         $ne->set_source_alias('last', 'nonexisting');
         $this->assertTrue(false, 'base_element_struct_exception expected');
     } catch (exception $e) {
         $this->assertTrue($e instanceof base_element_struct_exception);
         $this->assertEquals($e->errorcode, 'incorrectaliasfinalnamenotfound');
         $this->assertEquals($e->a, 'nonexisting');
     }
     // Try various incorrect paths specifying source
     $ne = new backup_nested_element('test', 'one', 'two', 'three');
     try {
         $ne->set_source_table('forum', array('/test/subtest'));
         $this->assertTrue(false, 'base_element_struct_exception expected');
     } catch (exception $e) {
         $this->assertTrue($e instanceof base_element_struct_exception);
         $this->assertEquals($e->errorcode, 'baseelementincorrectfinalorattribute');
         $this->assertEquals($e->a, 'subtest');
     }
     try {
         $ne->set_source_table('forum', array('/wrongtest'));
         $this->assertTrue(false, 'base_element_struct_exception expected');
     } catch (exception $e) {
         $this->assertTrue($e instanceof base_element_struct_exception);
         $this->assertEquals($e->errorcode, 'baseelementincorrectgrandparent');
         $this->assertEquals($e->a, 'wrongtest');
     }
     try {
         $ne->set_source_table('forum', array('../nonexisting'));
         $this->assertTrue(false, 'base_element_struct_exception expected');
     } catch (exception $e) {
         $this->assertTrue($e instanceof base_element_struct_exception);
         $this->assertEquals($e->errorcode, 'baseelementincorrectparent');
         $this->assertEquals($e->a, '..');
     }
     // Try various incorrect file annotations
     $ne = new backup_nested_element('test', 'one', 'two', 'three');
     $ne->annotate_files('test', 'filearea', null);
     try {
         $ne->annotate_files('test', 'filearea', null);
         // Try to add annotations twice
         $this->assertTrue(false, 'base_element_struct_exception expected');
     } catch (exception $e) {
         $this->assertTrue($e instanceof base_element_struct_exception);
         $this->assertEquals($e->errorcode, 'annotate_files_duplicate_annotation');
         $this->assertEquals($e->a, 'test/filearea/');
     }
     $ne = new backup_nested_element('test', 'one', 'two', 'three');
     try {
         $ne->annotate_files('test', 'filearea', 'four');
         // Incorrect element
         $this->assertTrue(false, 'base_element_struct_exception expected');
     } catch (exception $e) {
         $this->assertTrue($e instanceof base_element_struct_exception);
         $this->assertEquals($e->errorcode, 'baseelementincorrectfinalorattribute');
         $this->assertEquals($e->a, 'four');
     }
     // Try to add incorrect element to backup_optigroup
     $bog = new backup_optigroup('test');
     try {
         $bog->add_child(new backup_nested_element('test2'));
         $this->assertTrue(false, 'base_optigroup_exception expected');
     } catch (exception $e) {
         $this->assertTrue($e instanceof base_optigroup_exception);
         $this->assertEquals($e->errorcode, 'optigroup_element_incorrect');
         $this->assertEquals($e->a, 'backup_nested_element');
     }
     $bog = new backup_optigroup('test');
     try {
         $bog->add_child('test2');
         $this->assertTrue(false, 'base_optigroup_exception expected');
     } catch (exception $e) {
         $this->assertTrue($e instanceof base_optigroup_exception);
         $this->assertEquals($e->errorcode, 'optigroup_element_incorrect');
         $this->assertEquals($e->a, 'non object');
     }
     try {
         $bog = new backup_optigroup('test', new stdclass());
         $this->assertTrue(false, 'base_optigroup_exception expected');
     } catch (exception $e) {
         $this->assertTrue($e instanceof base_optigroup_exception);
         $this->assertEquals($e->errorcode, 'optigroup_elements_incorrect');
     }
     // Try a wrong processor with backup_optigroup
     $bog = new backup_optigroup('test');
     try {
         $bog->process(new stdclass());
         $this->assertTrue(false, 'base_element_struct_exception expected');
     } catch (exception $e) {
         $this->assertTrue($e instanceof base_element_struct_exception);
         $this->assertEquals($e->errorcode, 'incorrect_processor');
     }
     // Try duplicating used elements with backup_optigroup
     // Adding top->down
     $bog = new backup_optigroup('test', null, true);
     $boge1 = new backup_optigroup_element('boge1');
     $boge2 = new backup_optigroup_element('boge2');
     $ne1 = new backup_nested_element('ne1');
     $ne2 = new backup_nested_element('ne1');
     $bog->add_child($boge1);
     $bog->add_child($boge2);
     $boge1->add_child($ne1);
     try {
         $boge2->add_child($ne2);
         $this->assertTrue(false, 'base_optigroup_exception expected');
     } catch (exception $e) {
         $this->assertTrue($e instanceof base_optigroup_exception);
         $this->assertEquals($e->errorcode, 'multiple_optigroup_duplicate_element');
         $this->assertEquals($e->a, 'ne1');
     }
     // Adding down->top
     $bog = new backup_optigroup('test', null, true);
     $boge1 = new backup_optigroup_element('boge1');
     $boge2 = new backup_optigroup_element('boge2');
     $ne1 = new backup_nested_element('ne1');
     $ne2 = new backup_nested_element('ne1');
     $boge1->add_child($ne1);
     $boge2->add_child($ne2);
     $bog->add_child($boge1);
     try {
         $bog->add_child($boge2);
         $this->assertTrue(false, 'base_element_struct_exception expected');
     } catch (exception $e) {
         $this->assertTrue($e instanceof base_element_struct_exception);
         $this->assertEquals($e->errorcode, 'baseelementexisting');
         $this->assertEquals($e->a, 'ne1');
     }
 }