tips:fixmtime
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
tips:fixmtime [2008-09-01 03:21] – added PHP script that fixes timestamps 89.210.228.96 | tips:fixmtime [2023-08-17 19:17] (current) – [PHP script] 2804:14c:6324:8204:3157:1995:f6:a0e2 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Fix modification times based on timestamps ====== | ||
+ | |||
+ | Occasionally you may want to move your dokuwikis to another host. | ||
+ | To move your data, you will use things | ||
+ | like '' | ||
+ | the file modification times of your pages may be modified, and | ||
+ | they may no longer match the timestamps that are | ||
+ | created by dokuwiki as meta-information. | ||
+ | |||
+ | The resulting symptom is that the actual author of a page | ||
+ | will no longer be displayed. You will see an '' | ||
+ | instead. | ||
+ | |||
+ | To fix this, the file modification times have to be updated | ||
+ | according to the timestamps. | ||
+ | |||
+ | ===== Python Script ===== | ||
+ | |||
+ | The following is a (throw-away) python script that does this. Run | ||
+ | it from within the '' | ||
+ | |||
+ | <code python> | ||
+ | |||
+ | import os | ||
+ | path = os.path | ||
+ | |||
+ | os.stat_float_times(False) | ||
+ | |||
+ | meta = path.join(os.pardir, | ||
+ | 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, | ||
+ | if not path.isfile(changelog): | ||
+ | print " | ||
+ | continue | ||
+ | timestamp = 0 | ||
+ | for line in open(changelog): | ||
+ | timestamp = int(line.split()[0]) | ||
+ | file = path.join(root, | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | os.utime(file, | ||
+ | print " | ||
+ | |||
+ | </ | ||
+ | |||
+ | ===== PHP script ===== | ||
+ | |||
+ | The following is a PHP script that fixes modification times based on changelog timestamps this. **Run it from within DokuWiki installation directory.** | ||
+ | |||
+ | <code PHP> | ||
+ | <? | ||
+ | /** | ||
+ | * Fix modification times based on timestamps. Run from within DokuWiki installation directory. | ||
+ | * @Author: dreamlusion < | ||
+ | * last modified: 2008-09-05 4:15:00 | ||
+ | * updated by Daniel " | ||
+ | */ | ||
+ | function WalkDirectory($parentDirectory) { | ||
+ | global $_weeds; | ||
+ | |||
+ | foreach(array_diff(scandir($parentDirectory), | ||
+ | { | ||
+ | $path = $parentDirectory . '/' | ||
+ | |||
+ | if(is_dir($path)) | ||
+ | { | ||
+ | WalkDirectory($path); | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | // Calculate changes file path. | ||
+ | $path_parts = pathinfo($path); | ||
+ | |||
+ | // Remove pages path. | ||
+ | global $_pagesPath; | ||
+ | $relativePath = substr($path_parts[' | ||
+ | |||
+ | // Add < | ||
+ | $filename = $path_parts[' | ||
+ | $relativePath .= '/' | ||
+ | |||
+ | global $_metaPath; | ||
+ | $changelog = $_metaPath . '/' | ||
+ | |||
+ | if (is_file($changelog)) | ||
+ | { | ||
+ | $handle = @fopen($changelog, | ||
+ | if ($handle) { | ||
+ | while (!feof($handle)) { | ||
+ | $buffer = fgets($handle); | ||
+ | preg_match('/ | ||
+ | |||
+ | if ( isset($matches[' | ||
+ | $timestamp = $matches[' | ||
+ | |||
+ | } | ||
+ | fclose($handle); | ||
+ | } | ||
+ | |||
+ | // At this point we have our timestamp. | ||
+ | echo ' | ||
+ | echo '& | ||
+ | echo '& | ||
+ | if (touch($path, | ||
+ | { | ||
+ | // 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 '& | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | echo '& | ||
+ | } | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | echo ' | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | $_weeds = array(' | ||
+ | $_pagesPath = getcwd() . '/ | ||
+ | $_metaPath = getcwd() . '/ | ||
+ | |||
+ | WalkDirectory($_pagesPath); | ||
+ | |||
+ | ?> | ||
+ | </ | ||
tips/fixmtime.txt · Last modified: 2023-08-17 19:17 by 2804:14c:6324:8204:3157:1995:f6:a0e2