4 * Updates all files within our jurisdiction.
5 * @note This wants to be in a post-commit hook!
10 $xc = XHTMLCompiler
::getInstance();
12 // if in command line mode, allow more options
14 if ($cli = (php_sapi_name() === 'cli')) {
16 $type = isset($argv[1]) ?
$argv[1] : 'normal'; // see below
18 header('Content-type: text/plain');
21 // display a help file
22 if ($type == 'help') {
24 'hc-update.php [type] -- Updates compiled HTML files.
26 . normal : update existing files, remove orphans (default)
27 . all : normal + create files without cached output
28 . force : regenerate all files
29 . clean : remove all cache files';
34 if ($type == 'clean') {
35 $files = scan_dirs_for_pages('.html', $xc->getConf('allowed_dirs'));
36 foreach ($files as $file) {
37 if (is_created_by_us($file)) {
41 exit('Removed all cache files.');
45 list($files, $src_files) = scan_dirs_for_pages(
46 array('.html', '.xhtml'), $xc->getConf('allowed_dirs')
54 foreach ($files as $file) {
55 $page = new XHTMLCompiler_Page($file, true);
56 // we're only updating files, not creating new ones
57 if ($page->isSourceExistent()) {
59 // don't do it for force, since it's handled below
61 $page->isCacheExistent() &&
65 $updated[] = $page->getCachePath();
67 } elseif (is_created_by_us($page->getCachePath())) {
68 unlink($page); // orphan
69 $orphans[] = $page->getCachePath();
73 foreach ($src_files as $file) {
74 $page = new XHTMLCompiler_Page($file);
75 if ($type == 'all' && !$page->isCacheExistent()) {
76 // generate a new page
78 $created[] = $page->getCachePath();
79 } elseif ($type == 'force') {
81 $updated[] = $page->getCachePath();
86 if (empty($updated)) $updated[] = '(none)';
87 echo wordwrap('Updated pages: ' . implode(', ', $updated)) . PHP_EOL
;
89 if (empty($orphans)) $orphans[] = '(none)';
90 echo wordwrap('Removed orphans: ' . implode(', ', $orphans)) . PHP_EOL
;
92 if ($cli && ($type != 'force')) {
93 if (empty($created)) $created[] = '(none)';
94 echo wordwrap('Created pages: ' . implode(', ', $created)) . PHP_EOL
;