本文整理汇总了PHP中backup_controller_dbops::encode_backup_temp_info方法的典型用法代码示例。如果您正苦于以下问题:PHP backup_controller_dbops::encode_backup_temp_info方法的具体用法?PHP backup_controller_dbops::encode_backup_temp_info怎么用?PHP backup_controller_dbops::encode_backup_temp_info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类backup_controller_dbops
的用法示例。
在下文中一共展示了backup_controller_dbops::encode_backup_temp_info方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_backup_controller_dbops
function test_backup_controller_dbops()
{
global $DB;
$dbman = $DB->get_manager();
// Going to use some database_manager services for testing
// Instantiate non interactive backup_controller
$bc = new mock_backup_controller4dbops(backup::TYPE_1ACTIVITY, $this->moduleid, backup::FORMAT_MOODLE, backup::INTERACTIVE_NO, backup::MODE_GENERAL, $this->userid);
$this->assertTrue($bc instanceof backup_controller);
// Calculate checksum
$checksum = $bc->calculate_checksum();
$this->assertEquals(strlen($checksum), 32);
// is one md5
// save controller
$recid = backup_controller_dbops::save_controller($bc, $checksum);
$this->assertNotEmpty($recid);
// save it again (should cause update to happen)
$recid2 = backup_controller_dbops::save_controller($bc, $checksum);
$this->assertNotEmpty($recid2);
$this->assertEquals($recid, $recid2);
// Same record in both save operations
// Try incorrect checksum
$bc = new mock_backup_controller4dbops(backup::TYPE_1ACTIVITY, $this->moduleid, backup::FORMAT_MOODLE, backup::INTERACTIVE_NO, backup::MODE_GENERAL, $this->userid);
$checksum = $bc->calculate_checksum();
try {
$recid = backup_controller_dbops::save_controller($bc, 'lalala');
$this->assertTrue(false, 'backup_dbops_exception expected');
} catch (exception $e) {
$this->assertTrue($e instanceof backup_dbops_exception);
$this->assertEquals($e->errorcode, 'backup_controller_dbops_saving_checksum_mismatch');
}
// Try to save non backup_controller object
$bc = new stdclass();
try {
$recid = backup_controller_dbops::save_controller($bc, 'lalala');
$this->assertTrue(false, 'backup_controller_exception expected');
} catch (exception $e) {
$this->assertTrue($e instanceof backup_controller_exception);
$this->assertEquals($e->errorcode, 'backup_controller_expected');
}
// save and load controller (by backupid). Then compare
$bc = new mock_backup_controller4dbops(backup::TYPE_1ACTIVITY, $this->moduleid, backup::FORMAT_MOODLE, backup::INTERACTIVE_NO, backup::MODE_GENERAL, $this->userid);
$checksum = $bc->calculate_checksum();
// Calculate checksum
$backupid = $bc->get_backupid();
$this->assertEquals(strlen($backupid), 32);
// is one md5
$recid = backup_controller_dbops::save_controller($bc, $checksum);
// save controller
$newbc = backup_controller_dbops::load_controller($backupid);
// load controller
$this->assertTrue($newbc instanceof backup_controller);
$newchecksum = $newbc->calculate_checksum();
$this->assertEquals($newchecksum, $checksum);
// try to load non-existing controller
try {
$bc = backup_controller_dbops::load_controller('1234567890');
$this->assertTrue(false, 'backup_dbops_exception expected');
} catch (exception $e) {
$this->assertTrue($e instanceof backup_dbops_exception);
$this->assertEquals($e->errorcode, 'backup_controller_dbops_nonexisting');
}
// backup_ids_temp table tests
// If, for any reason table exists, drop it
if ($dbman->table_exists('backup_ids_temp')) {
$dbman->drop_table(new xmldb_table('backup_ids_temp'));
}
// Check backup_ids_temp table doesn't exist
$this->assertFalse($dbman->table_exists('backup_ids_temp'));
// Create and check it exists
backup_controller_dbops::create_backup_ids_temp_table('testingid');
$this->assertTrue($dbman->table_exists('backup_ids_temp'));
// Drop and check it doesn't exists anymore
backup_controller_dbops::drop_backup_ids_temp_table('testingid');
$this->assertFalse($dbman->table_exists('backup_ids_temp'));
// Test encoding/decoding of backup_ids_temp,backup_files_temp encode/decode functions.
// We need to handle both objects and data elements.
$object = new stdClass();
$object->item1 = 10;
$object->item2 = 'a String';
$testarray = array($object, 10, null, 'string', array('a' => 'b', 1 => 1));
foreach ($testarray as $item) {
$encoded = backup_controller_dbops::encode_backup_temp_info($item);
$decoded = backup_controller_dbops::decode_backup_temp_info($encoded);
$this->assertEquals($item, $decoded);
}
}
示例2: set_backup_ids_record
public static function set_backup_ids_record($restoreid, $itemname, $itemid, $newitemid = 0, $parentitemid = null, $info = null)
{
// Build conditionally the extra record info
$extrarecord = array();
if ($newitemid != 0) {
$extrarecord['newitemid'] = $newitemid;
}
if ($parentitemid != null) {
$extrarecord['parentitemid'] = $parentitemid;
}
if ($info != null) {
$extrarecord['info'] = backup_controller_dbops::encode_backup_temp_info($info);
}
self::set_backup_ids_cached($restoreid, $itemname, $itemid, $extrarecord);
}