Commit | Line | Data |
---|---|---|
5e434adf ARW |
1 | <?php |
2 | ||
3 | /** | |
4 | * Create classes which are used for schema introspection. | |
5 | */ | |
6 | class CRM_Core_CodeGen_Reflection extends CRM_Core_CodeGen_BaseTask { | |
4ef04170 TO |
7 | |
8 | protected $checksum; | |
9 | ||
0f35babf TO |
10 | /** |
11 | * @var string | |
12 | */ | |
13 | private $raw; | |
14 | ||
4ef04170 TO |
15 | /** |
16 | * @return bool | |
17 | * TRUE if an update is needed. | |
18 | */ | |
19 | public function needsUpdate() { | |
20 | if (!file_exists($this->getAbsFileName())) { | |
21 | return TRUE; | |
22 | } | |
0f35babf | 23 | |
5079ecb1 TO |
24 | // Generating this file is fairly cheap, and we don't have robust heuristic |
25 | // for the checksum. | |
26 | // if ($this->getSchemaChecksum() !== self::extractRegex($this->getAbsFileName(), ';\(GenCodeChecksum:([a-zA-Z0-9]+)\);')) { | |
27 | // return TRUE; | |
28 | // } | |
0f35babf TO |
29 | |
30 | return !$this->isApproxPhpMatch( | |
31 | file_get_contents($this->getAbsFileName()), | |
32 | $this->getRaw()); | |
5e434adf ARW |
33 | } |
34 | ||
0f35babf | 35 | |
8246bca4 | 36 | /** |
37 | * Run generator. | |
38 | */ | |
4ef04170 TO |
39 | public function run() { |
40 | echo "Generating table list\n"; | |
5e434adf ARW |
41 | $template = new CRM_Core_CodeGen_Util_Template('php'); |
42 | $template->assign('tables', $this->tables); | |
5079ecb1 | 43 | $template->assign('genCodeChecksum', 'IGNORE'); |
4ef04170 TO |
44 | $template->run('listAll.tpl', $this->getAbsFileName()); |
45 | } | |
46 | ||
0f35babf TO |
47 | /** |
48 | * Generate the raw PHP code for the data file. | |
49 | * | |
50 | * @return string | |
51 | */ | |
52 | public function getRaw() { | |
53 | if (!$this->raw) { | |
54 | $template = new CRM_Core_CodeGen_Util_Template('php'); | |
55 | $template->assign('tables', $this->tables); | |
56 | $template->assign('genCodeChecksum', 'NEW'); | |
57 | $this->raw = $template->fetch('listAll.tpl'); | |
58 | } | |
59 | return $this->raw; | |
60 | } | |
61 | ||
4ef04170 | 62 | /** |
8246bca4 | 63 | * Get absolute file name. |
64 | * | |
4ef04170 TO |
65 | * @return string |
66 | */ | |
67 | protected function getAbsFileName() { | |
68 | return $this->config->CoreDAOCodePath . "AllCoreTables.data.php"; | |
69 | } | |
5e434adf | 70 | |
5079ecb1 TO |
71 | // /** |
72 | // * Get the checksum for the schema. | |
73 | // * | |
74 | // * @return string | |
75 | // */ | |
76 | // protected function getSchemaChecksum() { | |
77 | // if (!$this->checksum) { | |
78 | // CRM_Utils_Array::flatten($this->tables, $flat); | |
79 | // ksort($flat); | |
80 | // $this->checksum = md5(json_encode($flat)); | |
81 | // } | |
82 | // return $this->checksum; | |
83 | // } | |
96025800 | 84 | |
5e434adf | 85 | } |