public function set_execution($execution, $executiontime = 0) { $this->log('setting controller execution', backup::LOG_DEBUG); // TODO: Check valid execution mode // TODO: Check time in future // TODO: Check time = 0 if inmediate $this->execution = $execution; $this->executiontime = $executiontime; // Default destination chain (based on type/mode/execution) $this->destination = backup_factory::get_destination_chain($this->type, $this->id, $this->mode, $this->execution); // Default logger chain (based on interactive/execution) $this->logger = backup_factory::get_logger_chain($this->interactive, $this->execution, $this->backupid); }
function test_backup_factory() { global $CFG; // Default instantiate, all levels = backup::LOG_NONE // With debugdisplay enabled $CFG->debugdisplay = true; $logger1 = backup_factory::get_logger_chain(backup::INTERACTIVE_YES, backup::EXECUTION_INMEDIATE, 'test'); $this->assertTrue($logger1 instanceof error_log_logger); // 1st logger is error_log_logger $this->assertEqual($logger1->get_level(), backup::LOG_NONE); $logger2 = $logger1->get_next(); $this->assertTrue($logger2 instanceof output_indented_logger); // 2nd logger is output_indented_logger $this->assertEqual($logger2->get_level(), backup::LOG_NONE); $logger3 = $logger2->get_next(); $this->assertTrue($logger3 instanceof file_logger); // 3rd logger is file_logger $this->assertEqual($logger3->get_level(), backup::LOG_NONE); $logger4 = $logger3->get_next(); $this->assertTrue($logger4 instanceof database_logger); // 4th logger is database_logger $this->assertEqual($logger4->get_level(), backup::LOG_NONE); $logger5 = $logger4->get_next(); $this->assertTrue($logger5 === null); // With debugdisplay disabled $CFG->debugdisplay = false; $logger1 = backup_factory::get_logger_chain(backup::INTERACTIVE_YES, backup::EXECUTION_INMEDIATE, 'test'); $this->assertTrue($logger1 instanceof error_log_logger); // 1st logger is error_log_logger $this->assertEqual($logger1->get_level(), backup::LOG_NONE); $logger2 = $logger1->get_next(); $this->assertTrue($logger2 instanceof file_logger); // 2nd logger is file_logger $this->assertEqual($logger2->get_level(), backup::LOG_NONE); $logger3 = $logger2->get_next(); $this->assertTrue($logger3 instanceof database_logger); // 3rd logger is database_logger $this->assertEqual($logger3->get_level(), backup::LOG_NONE); $logger4 = $logger3->get_next(); $this->assertTrue($logger4 === null); // Instantiate with debugging enabled and $CFG->backup_error_log_logger_level not set $CFG->debugdisplay = true; $CFG->debug = DEBUG_DEVELOPER; unset($CFG->backup_error_log_logger_level); $logger1 = backup_factory::get_logger_chain(backup::INTERACTIVE_YES, backup::EXECUTION_INMEDIATE, 'test'); $this->assertTrue($logger1 instanceof error_log_logger); // 1st logger is error_log_logger $this->assertEqual($logger1->get_level(), backup::LOG_DEBUG); // and must have backup::LOG_DEBUG level // Set $CFG->backup_error_log_logger_level to backup::LOG_WARNING and test again $CFG->backup_error_log_logger_level = backup::LOG_WARNING; $logger1 = backup_factory::get_logger_chain(backup::INTERACTIVE_YES, backup::EXECUTION_INMEDIATE, 'test'); $this->assertTrue($logger1 instanceof error_log_logger); // 1st logger is error_log_logger $this->assertEqual($logger1->get_level(), backup::LOG_WARNING); // and must have backup::LOG_WARNING level // Instantiate in non-interactive mode, output_indented_logger must be out $logger1 = backup_factory::get_logger_chain(backup::INTERACTIVE_NO, backup::EXECUTION_INMEDIATE, 'test'); $logger2 = $logger1->get_next(); $this->assertTrue($logger2 instanceof file_logger); // 2nd logger is file_logger (output_indented_logger skiped) // Define extra file logger and instantiate, should be 5th and last logger $CFG->backup_file_logger_extra = '/tmp/test.html'; $CFG->backup_file_logger_level_extra = backup::LOG_NONE; $logger1 = backup_factory::get_logger_chain(backup::INTERACTIVE_YES, backup::EXECUTION_INMEDIATE, 'test'); $logger2 = $logger1->get_next(); $logger3 = $logger2->get_next(); $logger4 = $logger3->get_next(); $logger5 = $logger4->get_next(); $this->assertTrue($logger5 instanceof file_logger); // 5rd logger is file_logger (extra) $this->assertEqual($logger3->get_level(), backup::LOG_NONE); $logger6 = $logger5->get_next(); $this->assertTrue($logger6 === null); }