CRM_Core_CodeGen_Util_Smarty::singleton()->setPluginDirs($smartyPluginDirs);
- $versionFile = "version.xml";
+ $versionFile = $this->phpCodePath . "/xml/version.xml";
$versionXML = CRM_Core_CodeGen_Util_Xml::parse($versionFile);
$this->db_version = $versionXML->version_no;
$this->buildVersion = preg_replace('/^(\d{1,2}\.\d{1,2})\.(\d{1,2}|\w{4,7})$/i', '$1', $this->db_version);
exit();
}
- $specification = new CRM_Core_CodeGen_Specification();
- $specification->parse($this->schemaPath, $this->buildVersion);
- # cheese:
- $this->database = $specification->database;
- $this->tables = $specification->tables;
-
foreach ($this->getTasks() as $task) {
if (getenv('GENCODE_FORCE') || $task->needsUpdate()) {
$task->run();
* @throws \Exception
*/
public function getTasks() {
+ $this->init();
+
$tasks = array();
$tasks[] = new CRM_Core_CodeGen_Config($this);
$tasks[] = new CRM_Core_CodeGen_Version($this);
return $this->sourceDigest;
}
+ protected function init() {
+ if (!$this->database || !$this->tables) {
+ $specification = new CRM_Core_CodeGen_Specification();
+ $specification->parse($this->schemaPath, $this->buildVersion);
+ # cheese:
+ $this->database = $specification->database;
+ $this->tables = $specification->tables;
+ }
+ }
+
}
--- /dev/null
+<?php
+
+/**
+ * Class CRM_Core_CodeGen_FreshnessTest
+ * @group headless
+ *
+ * Ensure that any files which are autogenerated AND which are
+ * committed to git are ALSO up-to-date.
+ */
+class CRM_Core_CodeGen_FreshnessTest extends CiviUnitTestCase {
+
+ public function testDAOs() {
+ $path = rtrim($GLOBALS['civicrm_root'], '/');
+
+ $genCode = new CRM_Core_CodeGen_Main(
+ $path . '/CRM/Core/DAO/', // $CoreDAOCodePath
+ $path . '/sql/', // $sqlCodePath
+ $path . '/', // $phpCodePath
+ $path . '/templates/', // $tplCodePath
+ array(
+ // smarty plugin dirs
+ $path . '/packages/Smarty/plugins',
+ $path . '/CRM/Core/Smarty/plugins',
+ ),
+ CIVICRM_UF, // cms
+ NULL, // db version
+ $path . '/xml/schema/Schema.xml', // schema file
+ NULL // path to digest file
+ );
+
+ $tasks = $genCode->getTasks();
+ $names = array();
+ foreach ($tasks as $task) {
+ if ($task instanceof CRM_Core_CodeGen_DAO) {
+ $names[] = $task->name;
+ $this->assertFalse($task->needsUpdate(),
+ "Expect DAO for {$task->name} is up-to-date.");
+ }
+ }
+
+ // Pick some example to ensure the loop ran with real values.
+ $this->assertTrue(in_array('civicrm_contact', $names),
+ 'Expect the list of tables to include civicrm_contact');
+ }
+
+}