From: Tim Otten Date: Wed, 27 Jul 2016 07:26:00 +0000 (-0700) Subject: CRM-14885 - CRM_Core_CodeGen - Allow tasks to define `needsUpdate()` X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=ce22c2069c1aae27acb377115f917a6efdf3bf0e;p=civicrm-core.git CRM-14885 - CRM_Core_CodeGen - Allow tasks to define `needsUpdate()` --- diff --git a/CRM/Core/CodeGen/BaseTask.php b/CRM/Core/CodeGen/BaseTask.php index 5bff345413..f220415bd0 100644 --- a/CRM/Core/CodeGen/BaseTask.php +++ b/CRM/Core/CodeGen/BaseTask.php @@ -29,4 +29,12 @@ abstract class CRM_Core_CodeGen_BaseTask implements CRM_Core_CodeGen_ITask { $this->tables = $this->config->tables; } + /** + * @return bool + * TRUE if an update is needed. + */ + public function needsUpdate() { + return TRUE; + } + } diff --git a/CRM/Core/CodeGen/ITask.php b/CRM/Core/CodeGen/ITask.php index 4797ca2629..c5338c29c5 100644 --- a/CRM/Core/CodeGen/ITask.php +++ b/CRM/Core/CodeGen/ITask.php @@ -10,4 +10,10 @@ interface CRM_Core_CodeGen_ITask { */ public function run(); + /** + * @return bool + * TRUE if an update is needed. + */ + public function needsUpdate(); + } diff --git a/CRM/Core/CodeGen/Main.php b/CRM/Core/CodeGen/Main.php index 0fdab711a6..bb33c75608 100644 --- a/CRM/Core/CodeGen/Main.php +++ b/CRM/Core/CodeGen/Main.php @@ -14,6 +14,20 @@ class CRM_Core_CodeGen_Main { var $tplCodePath; var $schemaPath; // ex: schema/Schema.xml + /** + * Definitions of all tables. + * + * @var array + * Ex: $tables['civicrm_address_format']['className'] = 'CRM_Core_DAO_AddressFormat'; + */ + var $tables; + + /** + * @var array + * Ex: $database['tableAttributes_modern'] = "ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci"; + */ + var $database; + /** * @var string|NULL path in which to store a marker that indicates the last execution of * GenCode. If a matching marker already exists, GenCode doesn't run. @@ -23,7 +37,7 @@ class CRM_Core_CodeGen_Main { /** * @var string|NULL a digest of the inputs to the code-generator (eg the properties and source files) */ - var $digest; + var $sourceDigest; /** * @param $CoreDAOCodePath @@ -42,7 +56,7 @@ class CRM_Core_CodeGen_Main { $this->phpCodePath = $phpCodePath; $this->tplCodePath = $tplCodePath; $this->digestPath = $digestPath; - $this->digest = NULL; + $this->sourceDigest = NULL; // default cms is 'drupal', if not specified $this->cms = isset($argCms) ? strtolower($argCms) : 'drupal'; @@ -88,7 +102,9 @@ Alternatively you can get a version of CiviCRM that matches your PHP version $this->tables = $specification->tables; foreach ($this->getTasks() as $task) { - $task->run(); + if (getenv('GENCODE_FORCE') || $task->needsUpdate()) { + $task->run(); + } } } @@ -132,4 +148,23 @@ Alternatively you can get a version of CiviCRM that matches your PHP version return TRUE; } + /** + * Compute a digest based on the GenCode logic (PHP/tpl). + * + * @return string + */ + public function getSourceDigest() { + if ($this->sourceDigest === NULL) { + $srcDir = CRM_Core_CodeGen_Util_File::findCoreSourceDir(); + $files = CRM_Core_CodeGen_Util_File::findManyFiles(array( + array("$srcDir/CRM/Core/CodeGen", '*.php'), + array("$srcDir/xml", "*.php"), + array("$srcDir/xml", "*.tpl"), + )); + + $this->sourceDigest = CRM_Core_CodeGen_Util_File::digestAll($files); + } + return $this->sourceDigest; + } + } diff --git a/CRM/Core/CodeGen/Util/File.php b/CRM/Core/CodeGen/Util/File.php index 98680958b8..a7d5e1e456 100644 --- a/CRM/Core/CodeGen/Util/File.php +++ b/CRM/Core/CodeGen/Util/File.php @@ -90,6 +90,7 @@ class CRM_Core_CodeGen_Util_File { list ($dir, $pattern) = $pair; $files = array_merge($files, CRM_Utils_File::findFiles($dir, $pattern)); } + sort($files); return $files; }