4 class SchemaGenerator
{
7 * Return translated SQL content using tpl, mainly contain SQL codes on table CREATE/DROP
9 * @param string $srcPath
10 * @param array $database
11 * @param array $tables
14 public static function generateCreateSql($srcPath, $database, $tables) {
15 $template = new Template($srcPath, 'sql');
17 $template->assign('database', $database);
18 $template->assign('tables', $tables);
19 $dropOrder = array_reverse(array_keys($tables));
20 $template->assign('dropOrder', $dropOrder);
21 $template->assign('mysql', 'modern');
23 return $template->getContent('schema.tpl');
27 * Generate an example set of data, including the basic data as well
28 * as some example records/entities (e.g. case-types, membership types).
30 * @param string $srcPath
34 public static function generateSampleData($srcPath) {
35 $versionFile = implode(DIRECTORY_SEPARATOR
, [$srcPath, 'xml', 'version.xml']);
36 $xml = \CRM_Core_CodeGen_Util_Xml
::parse($versionFile);
38 $template = new Template($srcPath, 'sql');
39 $template->assign('db_version', $xml->version_no
);
41 // If you're going to use the full data generator...
42 // "DROP TABLE IF EXISTS zipcodes"
43 // .... file_get_contents($sqlPath . DIRECTORY_SEPARATOR . 'zipcodes.mysql')...
46 'civicrm_country.tpl',
47 'civicrm_state_province.tpl',
48 'civicrm_currency.tpl',
53 'civicrm_version_sql.tpl',
54 'civicrm_navigation.tpl',
57 // DROP TABLE IF EXISTS zipcodes;
59 return $template->getConcatContent($sections);
63 * Generate a minimalist set of basic data, such as
64 * common option-values and countries.
66 * @param string $srcPath
71 public static function generateBasicData($srcPath) {
72 $versionFile = implode(DIRECTORY_SEPARATOR
, [$srcPath, 'xml', 'version.xml']);
73 $xml = \CRM_Core_CodeGen_Util_Xml
::parse($versionFile);
75 $template = new Template($srcPath, 'sql');
76 $template->assign('db_version', $xml->version_no
);
79 'civicrm_country.tpl',
80 'civicrm_state_province.tpl',
81 'civicrm_currency.tpl',
84 'civicrm_version_sql.tpl',
85 'civicrm_navigation.tpl',
87 return $template->getConcatContent($sections);