Remove unused return value.
[xhtml-compiler.git] / update.php
blob43300ccf8ae9586c929364f3640df9257d306c42
1 <?php
3 /**
4 * Updates all files within our jurisdiction.
5 * @note This wants to be in a post-commit hook!
6 */
8 require 'common.php';
10 // if in command line mode, allow more options
11 $type = 'normal';
12 if ($cli = (php_sapi_name() === 'cli')) {
13 set_time_limit(0);
14 $type = isset($argv[1]) ? $argv[1] : 'normal'; // see below
15 } else {
16 header('Content-type: text/plain');
19 // display a help file
20 if ($type == 'help') {
21 echo
22 'hc-update.php [type] -- Updates compiled HTML files.
23 [type] is:
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';
28 exit;
31 // clean up the cache
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)) {
36 unlink($file);
39 exit('Removed all cache files.');
42 // regular processing
43 list($files, $src_files) = scan_dirs_for_pages(
44 array('.html', '.xhtml'), $allowed_dirs
47 // status arrays
48 $updated = array();
49 $created = array();
50 $orphans = array();
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)) {
56 if (
57 // don't do it for force, since it's handled below
58 $type != 'force' &&
59 is_file($page) &&
60 is_cache_stale($page, $page_src)
61 ) {
62 generate_page($page, $page_src);
63 $updated[] = $page;
65 } elseif (is_created_by_us($page)) {
66 unlink($page); // orphan
67 $orphans[] = $page;
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);
76 $created[] = $page;
77 } elseif ($type == 'force') {
78 generate_page($page, $page_src);
79 $updated[] = $page;
83 // nice error message
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;