4 * Create SQL files to create and populate a new schema.
6 class CRM_Core_CodeGen_Schema
extends CRM_Core_CodeGen_BaseTask
{
9 public function __construct() {
10 parent
::__construct();
11 $this->locales
= $this->findLocales();
14 public function run() {
15 CRM_Core_CodeGen_Util_File
::createDir($this->config
->sqlCodePath
);
17 $this->generateCreateSql();
18 $this->generateDropSql();
20 $this->generateLocaleDataSql();
22 // also create the archive tables
23 // $this->generateCreateSql('civicrm_archive.mysql' );
24 // $this->generateDropSql('civicrm_archive_drop.mysql');
26 $this->generateNavigation();
27 $this->generateSample();
31 * @param string $fileName
33 public function generateCreateSql($fileName = 'civicrm.mysql') {
34 echo "Generating sql file\n";
35 $template = new CRM_Core_CodeGen_Util_Template('sql');
37 $template->assign('database', $this->config
->database
);
38 $template->assign('tables', $this->tables
);
39 $dropOrder = array_reverse(array_keys($this->tables
));
40 $template->assign('dropOrder', $dropOrder);
41 $template->assign('mysql', 'modern');
43 $template->run('schema.tpl', $this->config
->sqlCodePath
. $fileName);
47 * @param string $fileName
49 public function generateDropSql($fileName = 'civicrm_drop.mysql') {
50 echo "Generating sql drop tables file\n";
51 $dropOrder = array_reverse(array_keys($this->tables
));
52 $template = new CRM_Core_CodeGen_Util_Template('sql');
53 $template->assign('dropOrder', $dropOrder);
54 $template->run('drop.tpl', $this->config
->sqlCodePath
. $fileName);
57 public function generateNavigation() {
58 echo "Generating navigation file\n";
59 $template = new CRM_Core_CodeGen_Util_Template('sql');
60 $template->run('civicrm_navigation.tpl', $this->config
->sqlCodePath
. "civicrm_navigation.mysql");
63 public function generateLocaleDataSql() {
64 $template = new CRM_Core_CodeGen_Util_Template('sql');
67 $oldTsLocale = $tsLocale;
68 foreach ($this->locales
as $locale) {
69 echo "Generating data files for $locale\n";
71 $template->assign('locale', $locale);
72 $template->assign('db_version', $this->config
->db_version
);
75 'civicrm_country.tpl',
76 'civicrm_state_province.tpl',
77 'civicrm_currency.tpl',
79 'civicrm_navigation.tpl',
80 'civicrm_version_sql.tpl',
83 $ext = ($locale != 'en_US' ?
".$locale" : '');
84 // write the initialize base-data sql script
85 $template->runConcat($sections, $this->config
->sqlCodePath
. "civicrm_data$ext.mysql");
87 // write the acl sql script
88 $template->run('civicrm_acl.tpl', $this->config
->sqlCodePath
. "civicrm_acl$ext.mysql");
90 $tsLocale = $oldTsLocale;
93 public function generateSample() {
94 $template = new CRM_Core_CodeGen_Util_Template('sql');
99 $template->runConcat($sections, $this->config
->sqlCodePath
. 'civicrm_sample.mysql');
101 $template->run('case_sample.tpl', $this->config
->sqlCodePath
. 'case_sample.mysql');
107 public function findLocales() {
108 require_once 'CRM/Core/Config.php';
109 $config = CRM_Core_Config
::singleton(FALSE);
111 $localeDir = CRM_Core_I18n
::getResourceDir();
112 if (file_exists($localeDir)) {
113 $locales = preg_grep('/^[a-z][a-z]_[A-Z][A-Z]$/', scandir($localeDir));
116 $localesMask = getenv('CIVICRM_LOCALES');
117 if (!empty($localesMask)) {
118 $mask = explode(',', $localesMask);
119 $locales = array_intersect($locales, $mask);
122 if (!in_array('en_US', $locales)) {
123 array_unshift($locales, 'en_US');