4 * Class CRM_Core_CodeGen_Main
6 class CRM_Core_CodeGen_Main
{
9 var $cms; // drupal, joomla, wordpress
15 var $schemaPath; // ex: schema/Schema.xml
18 * Definitions of all tables.
21 * Ex: $tables['civicrm_address_format']['className'] = 'CRM_Core_DAO_AddressFormat';
27 * Ex: $database['tableAttributes_modern'] = "ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci";
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.
38 * @var string|NULL a digest of the inputs to the code-generator (eg the properties and source files)
43 * @param $CoreDAOCodePath
53 public function __construct($CoreDAOCodePath, $sqlCodePath, $phpCodePath, $tplCodePath, $IGNORE, $argCms, $argVersion, $schemaPath, $digestPath) {
54 $this->CoreDAOCodePath
= $CoreDAOCodePath;
55 $this->sqlCodePath
= $sqlCodePath;
56 $this->phpCodePath
= $phpCodePath;
57 $this->tplCodePath
= $tplCodePath;
58 $this->digestPath
= $digestPath;
59 $this->sourceDigest
= NULL;
61 // default cms is 'drupal', if not specified
62 $this->cms
= isset($argCms) ?
strtolower($argCms) : 'drupal';
64 $versionFile = $this->phpCodePath
. "/xml/version.xml";
65 $versionXML = CRM_Core_CodeGen_Util_Xml
::parse($versionFile);
66 $this->db_version
= $versionXML->version_no
;
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;
73 $this->schemaPath
= $schemaPath;
77 * Automatically generate a variety of files.
79 public function main() {
80 echo "\ncivicrm_domain.version := " . $this->db_version
. "\n\n";
81 if ($this->buildVersion
< 1.1) {
82 echo "The Database is not compatible for this version";
86 if (substr(phpversion(), 0, 1) < 5) {
87 echo phpversion() . ', ' . substr(phpversion(), 0, 1) . "\n";
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
96 foreach ($this->getTasks() as $task) {
97 if (getenv('GENCODE_FORCE') ||
$task->needsUpdate()) {
105 * Array<CRM_Core_CodeGen_ITask>.
108 public function getTasks() {
112 $tasks[] = new CRM_Core_CodeGen_Config($this);
113 $tasks[] = new CRM_Core_CodeGen_Version($this);
114 $tasks[] = new CRM_Core_CodeGen_Reflection($this);
115 $tasks[] = new CRM_Core_CodeGen_Schema($this);
116 foreach (array_keys($this->tables
) as $name) {
117 $tasks[] = new CRM_Core_CodeGen_DAO($this, $name);
119 $tasks[] = new CRM_Core_CodeGen_I18n($this);
124 * Compute a digest based on the GenCode logic (PHP/tpl).
128 public function getSourceDigest() {
129 if ($this->sourceDigest
=== NULL) {
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"),
137 $this->sourceDigest
= CRM_Core_CodeGen_Util_File
::digestAll($files);
139 return $this->sourceDigest
;
142 protected function init() {
143 if (!$this->database ||
!$this->tables
) {
144 $specification = new CRM_Core_CodeGen_Specification();
145 $specification->parse($this->schemaPath
, $this->buildVersion
);
147 $this->database
= $specification->database
;
148 $this->tables
= $specification->tables
;