Merge pull request #16595 from seamuslee001/refactor_payment_processor_radio
[civicrm-core.git] / setup / src / Setup / SchemaGenerator.php
CommitLineData
4bcd4c62
TO
1<?php
2namespace Civi\Setup;
3
4class SchemaGenerator {
5
6 /**
7 * Return translated SQL content using tpl, mainly contain SQL codes on table CREATE/DROP
8 *
9 * @param string $srcPath
10 * @param array $database
11 * @param array $tables
12 * @return string
13 */
14 public static function generateCreateSql($srcPath, $database, $tables) {
15 $template = new Template($srcPath, 'sql');
16
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');
22
23 return $template->getContent('schema.tpl');
24 }
25
26 /**
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).
29 *
30 * @param string $srcPath
31 *
32 * @return string
33 */
34 public static function generateSampleData($srcPath) {
35 $versionFile = implode(DIRECTORY_SEPARATOR, [$srcPath, 'xml', 'version.xml']);
36 $xml = \CRM_Core_CodeGen_Util_Xml::parse($versionFile);
37
38 $template = new Template($srcPath, 'sql');
39 $template->assign('db_version', $xml->version_no);
40
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')...
44
45 $sections = [
46 'civicrm_country.tpl',
47 'civicrm_state_province.tpl',
48 'civicrm_currency.tpl',
49 'civicrm_data.tpl',
50 'civicrm_acl.tpl',
51 'civicrm_sample.tpl',
52 'case_sample.tpl',
53 'civicrm_version_sql.tpl',
54 'civicrm_navigation.tpl',
55 ];
56
57 // DROP TABLE IF EXISTS zipcodes;
58
59 return $template->getConcatContent($sections);
60 }
61
62 /**
63 * Generate a minimalist set of basic data, such as
64 * common option-values and countries.
65 *
66 * @param string $srcPath
67 *
68 * @return string
69 * SQL
70 */
71 public static function generateBasicData($srcPath) {
72 $versionFile = implode(DIRECTORY_SEPARATOR, [$srcPath, 'xml', 'version.xml']);
73 $xml = \CRM_Core_CodeGen_Util_Xml::parse($versionFile);
74
75 $template = new Template($srcPath, 'sql');
76 $template->assign('db_version', $xml->version_no);
77
78 $sections = [
79 'civicrm_country.tpl',
80 'civicrm_state_province.tpl',
81 'civicrm_currency.tpl',
82 'civicrm_data.tpl',
83 'civicrm_acl.tpl',
84 'civicrm_version_sql.tpl',
85 'civicrm_navigation.tpl',
86 ];
87 return $template->getConcatContent($sections);
88 }
89
90}