Skip to content
This repository has been archived by the owner on Aug 1, 2021. It is now read-only.

Commit

Permalink
Combine InstallSchema, AvailableTables
Browse files Browse the repository at this point in the history
The main issue here is that `schema.tpl` is getting the wrong data. It was getting the DB name

```php
generateCreateSql($model->srcPath, $model->db['database'], $model->tables)
```

But it should actually the full, parsed schema specification:

```
generateCreateSql($model->srcPath, $spec->database, $spec->tables)
```

So basically...  `InstallSchema` needs access to the full `$specification`
(which was only available in `AvailableTables`).  And I don't currently see
a use-case that requires exposing the schema as part of the installer model,
so I think it's simpler to merge `AvailableTables` into `InstallSchema`.
  • Loading branch information
totten committed Feb 16, 2018
1 parent f023e26 commit 1746232
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 46 deletions.
35 changes: 0 additions & 35 deletions plugins/init/AvailableTables.civi-setup.php

This file was deleted.

33 changes: 32 additions & 1 deletion plugins/installDatabase/InstallSchema.civi-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@
exit("Installation plugins must only be loaded by the installer.\n");
}

\Civi\Setup::dispatcher()
->addListener('civi.setup.checkRequirements', function (\Civi\Setup\Event\CheckRequirementsEvent $e) {
$m = $e->getModel();
$files = array(
'xmlMissing' => implode(DIRECTORY_SEPARATOR, [$m->srcPath, 'xml']),
'xmlSchemaMissing' => implode(DIRECTORY_SEPARATOR, [$m->srcPath, 'xml', 'schema', 'Schema.xml']),
'xmlVersionMissing' => implode(DIRECTORY_SEPARATOR, [$m->srcPath, 'xml', 'version.xml']),
);

foreach ($files as $key => $file) {
if (!file_exists($file)) {
$e->addError('system', $key, "Schema file is missing: \"$file\"");
}
}
});

\Civi\Setup::dispatcher()
->addListener('civi.setup.checkRequirements', function (\Civi\Setup\Event\CheckRequirementsEvent $e) {
\Civi\Setup::log()->info(sprintf('[%s] Handle %s', basename(__FILE__), 'checkRequirements'));
Expand Down Expand Up @@ -47,9 +63,10 @@
$model = $e->getModel();

$sqlPath = $model->srcPath . DIRECTORY_SEPARATOR . 'sql';
$spec = _installschema_getSpec($model->srcPath);

\Civi\Setup::log()->info(sprintf('[%s] generateCreateSql', basename(__FILE__)));
\Civi\Setup\DbUtil::sourceSQL($model->db, \Civi\Setup\DbUtil::generateCreateSql($model->srcPath, $model->db['database'], $model->tables));
\Civi\Setup\DbUtil::sourceSQL($model->db, \Civi\Setup\DbUtil::generateCreateSql($model->srcPath, $spec->database, $spec->tables));

\Civi\Setup::log()->info(sprintf('[%s] generateNavigation', basename(__FILE__)));
\Civi\Setup\DbUtil::sourceSQL($model->db, \Civi\Setup\DbUtil::generateNavigation($model->srcPath));
Expand All @@ -72,3 +89,17 @@
}

});

/**
* @param string $srcPath
* @return \CRM_Core_CodeGen_Specification
*/
function _installschema_getSpec($srcPath) {
$schemaFile = implode(DIRECTORY_SEPARATOR, [$srcPath, 'xml', 'schema', 'Schema.xml']);
$versionFile = implode(DIRECTORY_SEPARATOR, [$srcPath, 'xml', 'version.xml']);
$xmlBuilt = \CRM_Core_CodeGen_Util_Xml::parse($versionFile);
$buildVersion = preg_replace('/^(\d{1,2}\.\d{1,2})\.(\d{1,2}|\w{4,7})$/i', '$1', $xmlBuilt->version_no);
$specification = new \CRM_Core_CodeGen_Specification();
$specification->parse($schemaFile, $buildVersion, FALSE);
return $specification;
}
10 changes: 0 additions & 10 deletions src/Setup/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@
* Keys should be prefixed based on which plugin manages the field.
* Values must only be scalars (bool/int/string) and arrays.
* Ex: ['opt-in.version-check' => TRUE].
* @property array $tables
* List of CiviCRM tables extracted from xml schema files.
* Values must only be array.
* Ex: ['civicrm_contact', 'civicrm_group'].
*/
class Model {

Expand Down Expand Up @@ -154,12 +150,6 @@ public function __construct() {
'type' => 'array',
'value' => array(),
));
$this->addField(array(
'description' => 'CiviCRM Tables',
'name' => 'tables',
'type' => 'string',
'options' => array(),
));
}

/**
Expand Down

0 comments on commit 1746232

Please sign in to comment.