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