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