4 * Updates all files within our jurisdiction.
5 * @note This wants to be in a post-commit hook!
10 // if in command line mode, allow more options
12 if ($cli = (php_sapi_name() === 'cli')) {
14 $type = isset($argv[1]) ?
$argv[1] : 'normal'; // see below
16 header('Content-type: text/plain');
19 // display a help file
20 if ($type == 'help') {
22 'hc-update.php [type] -- Updates compiled HTML files.
24 . normal : update existing files, remove orphans (default)
25 . all : normal + create files without cached output
26 . force : regenerate all files
27 . clean : remove all cache files';
32 if ($type == 'clean') {
33 $files = scan_dirs_for_pages('.html', $allowed_dirs);
34 foreach ($files as $file) {
35 if (is_created_by_us($file)) {
39 exit('Removed all cache files.');
43 list($files, $src_files) = scan_dirs_for_pages(
44 array('.html', '.xhtml'), $allowed_dirs
52 foreach ($files as $file) {
53 list($page, $page_src) = calculate_page_and_src($file);
54 // we're only updating files, not creating new ones
55 if (is_file($page_src)) {
57 // don't do it for force, since it's handled below
60 is_cache_stale($page, $page_src)
62 generate_page($page, $page_src);
65 } elseif (is_created_by_us($page)) {
66 unlink($page); // orphan
71 foreach ($src_files as $file) {
72 list($page, $page_src) = calculate_page_and_src($file);
73 if ($type == 'all' && !is_file($page)) {
74 // generate a new page
75 generate_page($page, $page_src);
77 } elseif ($type == 'force') {
78 generate_page($page, $page_src);
84 if (empty($updated)) $updated[] = '(none)';
85 echo wordwrap('Updated pages: ' . implode(', ', $updated)) . PHP_EOL
;
87 if (empty($orphans)) $orphans[] = '(none)';
88 echo wordwrap('Removed orphans: ' . implode(', ', $orphans)) . PHP_EOL
;
90 if ($cli && ($type != 'force')) {
91 if (empty($created)) $created[] = '(none)';
92 echo wordwrap('Created pages: ' . implode(', ', $created)) . PHP_EOL
;