This repository was archived by the owner on Mar 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathworker.php
More file actions
executable file
·99 lines (78 loc) · 2.51 KB
/
Copy pathworker.php
File metadata and controls
executable file
·99 lines (78 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/**
*
* WARNING! The environment variables requested in config.php must be set in
* the environment of the user executing the worker (export command).
*/
/*
* @todo Cambiar repo.status(fail) por 'outdated', ya que el repo en sí no
* falla. Si un job falla, se usa la doc anterior, por tanto el repo siempre
* está correcto, aunque puede estar desactualizado si el último job falló. Hay
* una excepción a esto: si el primer trabajo al registrar el repo falla,
* debería quedar en estado new o algo así
*/
include 'config.php';
require 'db.php';
require 'misc.php';
//Init DB
$mysql = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD);
mysql_select_db(MYSQL_DATABASE, $mysql);
$job = db_select_pending_job();
if (!$job)
{
exit(1);
}
echo "\nStarting job #" . $job['id_job'] . "...\n";
db_update_job_status($job['id_job'], 'generating');
db_update_repo_status($job['id_repo'], 'generating');
list($user, $repo) = explode('/', $job['location']);
/*
* Grab the latest code
* @todo Repensar si es necesario el hash del changeset...
* @todo Si el pull devuelve "everything up-to-date" y ya hay documentación generada, NO VOLVER A GENERAR
* @todo Comprobar si hay changesets más recientes que el que se usó en el último job exitoso de este repo
*/
$repos_dir = __DIR__ . '/repos';
$repo_dir = "$repos_dir/$user/$repo";
if (!file_exists($repos_dir))
{
mkdir($repos_dir);
}
if (file_exists($repo_dir . '/.git'))
{
//If the repo is already cloned, update it
$cmd = command("cd $repo_dir && git pull 2>&1");
}
else
{
$cmd = command("cd $repos_dir && git clone git://github.com/$user/$repo.git $user/$repo 2>&1");
}
/*
* Generate the phpDoc
*/
$docs_dir = __DIR__ . '/docs';
$doc_dir = "$docs_dir/$user/$repo";
if (!file_exists($docs_dir))
{
mkdir($docs_dir);
}
/** @todo Do not remove the old docs until the new ones are succcesfully generated */
if (file_exists($doc_dir))
{
command("rm -rf $doc_dir");
}
/** @todo Store in a temporary dir, then remove the old docs if phpdoc returned success, and then move the new ones */
$cmd = command("phpdoc --extensions php --ignore-symlinks --title $user/$repo -d $repo_dir -t $doc_dir");
if (0 == $cmd->return_code)
{
db_update_job_status($job['id_job'], 'done', join("\n", $cmd->output));
db_update_repo_status($job['id_repo'], 'updated');
echo 'Succeed job #' . $job['id_job'] . "\n";
}
else
{
db_update_job_status($job['id_job'], 'fail');
db_update_repo_status($job['id_repo'], 'fail');
echo 'Failed job #' . $job['id_job'] . "\n";
}
exit(0);