Remove completed smoketest TODO.
[xhtml-compiler.git] / update.php
blob30e25b397d7c7a4f9b3961898441740293157dda
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 $xc = XHTMLCompiler::getInstance();
12 // if in command line mode, allow more options
13 $type = 'normal';
14 if ($cli = (php_sapi_name() === 'cli')) {
15 set_time_limit(0);
16 $type = isset($argv[1]) ? $argv[1] : 'normal'; // see below
17 } else {
18 header('Content-type: text/plain');
21 // display a help file
22 if ($type == 'help') {
23 echo
24 'hc-update.php [type] -- Updates compiled HTML files.
25 [type] is:
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 and dependency files';
30 exit;
33 // clean up the cache
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)) {
38 unlink($file);
41 $files = scan_dirs_for_pages('.xc-deps', $xc->getConf('allowed_dirs'));
42 foreach ($files as $file) {
43 unlink($file);
45 exit('Removed all cache and dependency files.');
48 // regular processing
49 list($files, $src_files) = scan_dirs_for_pages(
50 array('.html', '.xhtml'), $xc->getConf('allowed_dirs')
53 // status arrays
54 $updated = array();
55 $created = array();
56 $orphans = array();
58 foreach ($files as $file) {
59 $page = new XHTMLCompiler_Page($file, true);
60 // we're only updating files, not creating new ones
61 if ($page->isSourceExistent()) {
62 if (
63 // don't do it for force, since it's handled below
64 $type != 'force' &&
65 $page->isCacheExistent() &&
66 $page->isCacheStale()
67 ) {
68 $page->generate();
69 $updated[] = $page->getCachePath();
71 } elseif (is_created_by_us($page->getCachePath())) {
72 unlink($page); // orphan
73 $orphans[] = $page->getCachePath();
77 foreach ($src_files as $file) {
78 $page = new XHTMLCompiler_Page($file);
79 if ($type == 'all' && !$page->isCacheExistent()) {
80 // generate a new page
81 $page->generate();
82 $created[] = $page->getCachePath();
83 } elseif ($type == 'force') {
84 $page->generate();
85 $updated[] = $page->getCachePath();
89 // nice error message
90 if (empty($updated)) $updated[] = '(none)';
91 echo wordwrap('Updated pages: ' . implode(', ', $updated)) . PHP_EOL;
93 if (empty($orphans)) $orphans[] = '(none)';
94 echo wordwrap('Removed orphans: ' . implode(', ', $orphans)) . PHP_EOL;
96 if ($cli && ($type != 'force')) {
97 if (empty($created)) $created[] = '(none)';
98 echo wordwrap('Created pages: ' . implode(', ', $created)) . PHP_EOL;