====== Исправление времени правок по временным кодам ====== Если вы решили передвинуть сайт на другой хост, используя ''FTP'' и ''tar''-архивацию, время создания файлов изменится и перестанет совпадать с временными кодами в мета-информации. Характерный симптом - вместо автора актуальной правки в списке правок страниц появляется строчка ''внешнее изменение''. Нижеследующие скрипты восстанавливают эти несоответствия. ===== Вариант на Python ===== Этот скрипт запускать из папки ''data/pages''. import os path = os.path os.stat_float_times(False) meta = path.join(os.pardir, 'meta') assert path.isdir(meta) for root, dirs, filenames in os.walk(os.curdir): for filename in filenames: base, ext = path.splitext(filename) changelog = path.join(meta, root, base + ".changes") if not path.isfile(changelog): print "Changelog not found: %s" % changelog continue timestamp = 0 for line in open(changelog): timestamp = int(line.split()[0]) file = path.join(root, filename) print "updating %s" % file print " timestamp: %s" % timestamp print " old modification time: %s" % path.getmtime(file) os.utime(file, (timestamp, timestamp)) print " new modification time: %s" % path.getmtime(file) ===== Вариант на PHP ===== Этот скрипт запускать из установочной папки Dokuwiki. * last modified: 2008-09-05 4:15:00 */ function WalkDirectory($parentDirectory) { global $_weeds; foreach(array_diff(scandir($parentDirectory), $_weeds) as $directory) { $path = $parentDirectory . '/'. $directory; if(is_dir($path)) { WalkDirectory($path); } else { // Calculate changes file path. $path_parts = pathinfo($path); // Remove pages path. global $_pagesPath; $relativePath = substr($path_parts['dirname'], strlen($_pagesPath), strlen($path_parts['dirname'])); // Add .changes $filename = $path_parts['filename']; // Requires PHP 5.2.0 (http://gr2.php.net/manual/en/function.pathinfo.php) $relativePath .= '/' . $filename . '.' . 'changes'; global $_metaPath; $changelog = $_metaPath . '/' . $relativePath; if (is_file($changelog)) { $handle = @fopen($changelog, "r"); if ($handle) { while (!feof($handle)) { $buffer = fgets($handle); preg_match('/(?\d+)/', $buffer, $matches); if ($matches['timestamp'] != '') $timestamp = $matches['timestamp']; } fclose($handle); } // At this point we have our timestamp. echo 'Updating ' . $path . '
'; echo '    Timestamp in changelog: ' . $timestamp . '
'; echo '    Old modification time: ' . filemtime($path) . '
'; if (touch($path, $timestamp)) { // In my host, although the timestamp had changed successfully (checked manually), running filemtime($path) at this point // did not return the correct timestamp, so use I use $timestamp instead of filemtime($path) to avoid confusing the user. echo '    New modification time: ' . $timestamp . '
'; } else { echo '    Could not change modification time for page ' . $filename; } } else { echo 'Changelog not found: ' . $changelog . '
'; } } } } $_weeds = array('.', '..'); $_pagesPath = getcwd() . '/data/pages'; $_metaPath = getcwd() . '/data/meta'; WalkDirectory($_pagesPath); ?>