4 * Create SQL files to create and populate a new schema.
6 class CRM_Core_CodeGen_Schema
extends CRM_Core_CodeGen_BaseTask
{
9 * CRM_Core_CodeGen_Schema constructor.
11 * @param \CRM_Core_CodeGen_Main $config
13 public function __construct($config) {
14 parent
::__construct($config);
15 $this->locales
= $this->findLocales();
18 public function run() {
19 CRM_Core_CodeGen_Util_File
::createDir($this->config
->sqlCodePath
);
21 $this->generateCreateSql();
22 $this->generateDropSql();
24 $this->generateLocaleDataSql();
26 // also create the archive tables
27 // $this->generateCreateSql('civicrm_archive.mysql' );
28 // $this->generateDropSql('civicrm_archive_drop.mysql');
30 $this->generateNavigation();
31 $this->generateSample();
35 * @param string $fileName
37 public function generateCreateSql($fileName = 'civicrm.mysql') {
38 echo "Generating sql file\n";
39 $template = new CRM_Core_CodeGen_Util_Template('sql');
41 $template->assign('database', $this->config
->database
);
42 $template->assign('tables', $this->tables
);
43 $dropOrder = array_reverse(array_keys($this->tables
));
44 $template->assign('dropOrder', $dropOrder);
45 $template->assign('mysql', 'modern');
47 $template->run('schema.tpl', $this->config
->sqlCodePath
. $fileName);
51 * @param string $fileName
53 public function generateDropSql($fileName = 'civicrm_drop.mysql') {
54 echo "Generating sql drop tables file\n";
55 $dropOrder = array_reverse(array_keys($this->tables
));
56 $template = new CRM_Core_CodeGen_Util_Template('sql');
57 $template->assign('dropOrder', $dropOrder);
58 $template->run('drop.tpl', $this->config
->sqlCodePath
. $fileName);
61 public function generateNavigation() {
62 echo "Generating navigation file\n";
63 $template = new CRM_Core_CodeGen_Util_Template('sql');
64 $template->run('civicrm_navigation.tpl', $this->config
->sqlCodePath
. "civicrm_navigation.mysql");
67 public function generateLocaleDataSql() {
68 $template = new CRM_Core_CodeGen_Util_Template('sql');
71 $oldTsLocale = $tsLocale;
72 foreach ($this->locales
as $locale) {
73 echo "Generating data files for $locale\n";
75 $template->assign('locale', $locale);
76 $template->assign('db_version', $this->config
->db_version
);
79 'civicrm_country.tpl',
80 'civicrm_state_province.tpl',
81 'civicrm_currency.tpl',
83 'civicrm_navigation.tpl',
84 'civicrm_version_sql.tpl',
87 $ext = ($locale != 'en_US' ?
".$locale" : '');
88 // write the initialize base-data sql script
89 $template->runConcat($sections, $this->config
->sqlCodePath
. "civicrm_data$ext.mysql");
91 // write the acl sql script
92 $template->run('civicrm_acl.tpl', $this->config
->sqlCodePath
. "civicrm_acl$ext.mysql");
94 $tsLocale = $oldTsLocale;
97 public function generateSample() {
98 $template = new CRM_Core_CodeGen_Util_Template('sql');
100 'civicrm_sample.tpl',
103 $template->runConcat($sections, $this->config
->sqlCodePath
. 'civicrm_sample.mysql');
105 $template->run('case_sample.tpl', $this->config
->sqlCodePath
. 'case_sample.mysql');
111 public function findLocales() {
112 require_once 'CRM/Core/Config.php';
113 $config = CRM_Core_Config
::singleton(FALSE);
115 $localeDir = CRM_Core_I18n
::getResourceDir();
116 if (file_exists($localeDir)) {
117 $locales = preg_grep('/^[a-z][a-z]_[A-Z][A-Z]$/', scandir($localeDir));
120 $localesMask = getenv('CIVICRM_LOCALES');
121 if (!empty($localesMask)) {
122 $mask = explode(',', $localesMask);
123 $locales = array_intersect($locales, $mask);
126 if (!in_array('en_US', $locales)) {
127 array_unshift($locales, 'en_US');