Commit | Line | Data |
---|---|---|
e39816b5 ARW |
1 | <?php |
2 | ||
b5c2afd0 EM |
3 | /** |
4 | * Class CRM_Core_CodeGen_Main | |
5 | */ | |
e39816b5 | 6 | class CRM_Core_CodeGen_Main { |
518fa0ee SL |
7 | public $buildVersion; |
8 | public $db_version; | |
9 | /** | |
10 | * drupal, joomla, wordpress | |
11 | * @var string | |
12 | */ | |
13 | public $cms; | |
e39816b5 | 14 | |
518fa0ee SL |
15 | public $CoreDAOCodePath; |
16 | public $sqlCodePath; | |
17 | public $phpCodePath; | |
18 | public $tplCodePath; | |
19 | /** | |
20 | * ex: schema/Schema.xml | |
21 | * @var string | |
22 | */ | |
23 | public $schemaPath; | |
e39816b5 | 24 | |
ce22c206 TO |
25 | /** |
26 | * Definitions of all tables. | |
27 | * | |
28 | * @var array | |
29 | * Ex: $tables['civicrm_address_format']['className'] = 'CRM_Core_DAO_AddressFormat'; | |
30 | */ | |
518fa0ee | 31 | public $tables; |
ce22c206 TO |
32 | |
33 | /** | |
34 | * @var array | |
35 | * Ex: $database['tableAttributes_modern'] = "ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci"; | |
36 | */ | |
518fa0ee | 37 | public $database; |
ce22c206 | 38 | |
3530751a | 39 | /** |
cc101011 | 40 | * Path in which to store a marker that indicates the last execution of GenCode. |
41 | * | |
42 | * If a matching marker already exists, GenCode doesn't run. | |
43 | * | |
44 | * @var string|null | |
3530751a | 45 | */ |
518fa0ee | 46 | public $digestPath; |
3530751a TO |
47 | |
48 | /** | |
cc101011 | 49 | * Digest of the inputs to the code-generator (eg the properties and source files). |
50 | * | |
51 | * @var string|null | |
3530751a | 52 | */ |
518fa0ee | 53 | public $sourceDigest; |
3530751a | 54 | |
2558c2b0 EM |
55 | /** |
56 | * @param $CoreDAOCodePath | |
57 | * @param $sqlCodePath | |
58 | * @param $phpCodePath | |
59 | * @param $tplCodePath | |
90b9cb2c | 60 | * @param $IGNORE |
2558c2b0 EM |
61 | * @param $argCms |
62 | * @param $argVersion | |
63 | * @param $schemaPath | |
64 | * @param $digestPath | |
65 | */ | |
90b9cb2c | 66 | public function __construct($CoreDAOCodePath, $sqlCodePath, $phpCodePath, $tplCodePath, $IGNORE, $argCms, $argVersion, $schemaPath, $digestPath) { |
e39816b5 ARW |
67 | $this->CoreDAOCodePath = $CoreDAOCodePath; |
68 | $this->sqlCodePath = $sqlCodePath; | |
69 | $this->phpCodePath = $phpCodePath; | |
70 | $this->tplCodePath = $tplCodePath; | |
3530751a | 71 | $this->digestPath = $digestPath; |
ce22c206 | 72 | $this->sourceDigest = NULL; |
e39816b5 | 73 | |
5e434adf ARW |
74 | // default cms is 'drupal', if not specified |
75 | $this->cms = isset($argCms) ? strtolower($argCms) : 'drupal'; | |
e39816b5 | 76 | |
d18ee974 | 77 | $versionFile = $this->phpCodePath . "/xml/version.xml"; |
353ffa53 TO |
78 | $versionXML = CRM_Core_CodeGen_Util_Xml::parse($versionFile); |
79 | $this->db_version = $versionXML->version_no; | |
e39816b5 ARW |
80 | $this->buildVersion = preg_replace('/^(\d{1,2}\.\d{1,2})\.(\d{1,2}|\w{4,7})$/i', '$1', $this->db_version); |
81 | if (isset($argVersion)) { | |
82 | // change the version to that explicitly passed, if any | |
83 | $this->db_version = $argVersion; | |
84 | } | |
85 | ||
86 | $this->schemaPath = $schemaPath; | |
87 | } | |
88 | ||
e39816b5 | 89 | /** |
fe482240 | 90 | * Automatically generate a variety of files. |
e39816b5 | 91 | */ |
00be9182 | 92 | public function main() { |
86bfa4f6 | 93 | echo "\ncivicrm_domain.version := " . $this->db_version . "\n\n"; |
e39816b5 ARW |
94 | if ($this->buildVersion < 1.1) { |
95 | echo "The Database is not compatible for this version"; | |
96 | exit(); | |
97 | } | |
98 | ||
6ef04c72 | 99 | if (substr(phpversion(), 0, 1) < 5) { |
e39816b5 ARW |
100 | echo phpversion() . ', ' . substr(phpversion(), 0, 1) . "\n"; |
101 | echo " | |
102 | CiviCRM requires a PHP Version >= 5 | |
103 | Please upgrade your php / webserver configuration | |
104 | Alternatively you can get a version of CiviCRM that matches your PHP version | |
105 | "; | |
106 | exit(); | |
107 | } | |
108 | ||
bc02b97b | 109 | foreach ($this->getTasks() as $task) { |
ce22c206 | 110 | if (getenv('GENCODE_FORCE') || $task->needsUpdate()) { |
5e434adf | 111 | $task->run(); |
0db6c3e1 | 112 | } |
e39816b5 | 113 | } |
e39816b5 | 114 | } |
3530751a TO |
115 | |
116 | /** | |
a6c01b45 | 117 | * @return array |
bc02b97b TO |
118 | * Array<CRM_Core_CodeGen_ITask>. |
119 | * @throws \Exception | |
3530751a TO |
120 | */ |
121 | public function getTasks() { | |
d18ee974 TO |
122 | $this->init(); |
123 | ||
be2fb01f | 124 | $tasks = []; |
bc02b97b TO |
125 | $tasks[] = new CRM_Core_CodeGen_Config($this); |
126 | $tasks[] = new CRM_Core_CodeGen_Reflection($this); | |
127 | $tasks[] = new CRM_Core_CodeGen_Schema($this); | |
37254324 TO |
128 | foreach (array_keys($this->tables) as $name) { |
129 | $tasks[] = new CRM_Core_CodeGen_DAO($this, $name); | |
130 | } | |
bc02b97b TO |
131 | $tasks[] = new CRM_Core_CodeGen_I18n($this); |
132 | return $tasks; | |
3530751a TO |
133 | } |
134 | ||
135 | /** | |
ce22c206 | 136 | * Compute a digest based on the GenCode logic (PHP/tpl). |
3530751a TO |
137 | * |
138 | * @return string | |
139 | */ | |
ce22c206 TO |
140 | public function getSourceDigest() { |
141 | if ($this->sourceDigest === NULL) { | |
3530751a | 142 | $srcDir = CRM_Core_CodeGen_Util_File::findCoreSourceDir(); |
be2fb01f CW |
143 | $files = CRM_Core_CodeGen_Util_File::findManyFiles([ |
144 | ["$srcDir/CRM/Core/CodeGen", '*.php'], | |
145 | ["$srcDir/xml", "*.php"], | |
146 | ["$srcDir/xml", "*.tpl"], | |
147 | ]); | |
3530751a | 148 | |
ce22c206 | 149 | $this->sourceDigest = CRM_Core_CodeGen_Util_File::digestAll($files); |
3530751a | 150 | } |
ce22c206 | 151 | return $this->sourceDigest; |
3530751a | 152 | } |
693f0bff | 153 | |
d18ee974 TO |
154 | protected function init() { |
155 | if (!$this->database || !$this->tables) { | |
156 | $specification = new CRM_Core_CodeGen_Specification(); | |
157 | $specification->parse($this->schemaPath, $this->buildVersion); | |
158 | # cheese: | |
159 | $this->database = $specification->database; | |
160 | $this->tables = $specification->tables; | |
693f0bff | 161 | } |
693f0bff | 162 | } |
96025800 | 163 | |
e39816b5 | 164 | } |