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