function testKeyGenerator() { $this->assertEquals('b', getNextKey('a'), 'String after a is not "b"'); $this->assertEquals('aa', getNextKey('9'), 'Key after 9 is not "aa"'); $this->assertEquals('ijeue', getNextKey('ijeud'), 'Key after ijeud is not "ijeue"'); $this->assertEquals('12346', getNextKey('12345'), 'Key after 12345 is not "12346"'); $this->assertEquals('7dhfgbcvdfgftdyhg', getNextKey('7dhfgbcvdfgftdyhf'), 'Key after 7dhfgbcvdfgftdyhg is not "7dhfgbcvdfgftdyhg"'); }
function getNextKey($key = null, $tail = '') { global $range, $trans; // bad if ($key === null) { $key = getLastKey(); } if (empty($key)) { return "a{$tail}"; } $keylen = strlen($key); $lastChar = $key[$keylen - 1]; if ($lastChar != '9') { return substr($key, 0, $keylen - 1) . $range[$trans[$lastChar] + 1] . $tail; } else { return getNextKey(substr($key, 0, -1), "a{$tail}"); } }
/** * Checks if there is a next db to be dumped * * Sets the global flag $dump['backup_done'] * * @return void */ function checkForNextDB() { global $dump; // a check, if another db should be saved is at the end of the script // backup of actual db is done -> lets check if there is more to do $nextDb = getNextKey($dump['databases'], $dump['db_actual']); if ($nextDb !== false) { $dump['backup_done'] = 0; //-1 instead of 0 is needed for the execution of command before backup $dump['table_offset'] = -1; $dump['db_actual'] = $nextDb; $dump['part_offset'] = $dump['part'] - 1; } else { $dump['backup_done'] = 1; $dump['table_offset_total']--; } }