Skip to content

Commit

Permalink
Move config definitions out of DB into code (#1817)
Browse files Browse the repository at this point in the history
* Proof of concept. Probably still has bugs

* fix order and value setting

* more cleanup and upgrade script

* closes #1670

* Apply fixes from StyleCI

* fix sql style

* gettext for config descriptions

* more gettext

* fix annoying second refresh settings bug

* Apply fixes from StyleCI

* better null checking, and cleanup old code

* Remove special handling of country and timezone settings.  They are simple "choice" settings.

* Apply fixes from StyleCI

* move another country

* Fix issue with choices containing a space
  • Loading branch information
crossan007 authored and DawoudIO committed Jan 30, 2017
1 parent 870c98a commit ef1e054
Show file tree
Hide file tree
Showing 13 changed files with 477 additions and 489 deletions.
15 changes: 1 addition & 14 deletions locale/extract-db-locale-terms.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
$stringFiles = [];

$db = new PDO('mysql:host=localhost;dbname='.$db_name.';charset=utf8mb4', $db_username, $db_password);
$query = 'select DISTINCT cfg_tooltip as term, "" as translation, "config_cfg" as cntx from config_cfg
union all
select DISTINCT ucfg_tooltip as term, "" as translation, "userconfig_ucfg" as cntx from userconfig_ucfg
$query = 'select DISTINCT ucfg_tooltip as term, "" as translation, "userconfig_ucfg" as cntx from userconfig_ucfg
union all
select DISTINCT qry_Name as term, "" as translation, "query_qry" as cntx from query_qry
union all
Expand Down Expand Up @@ -40,17 +38,6 @@
file_put_contents($stringFile, "\r\n?>", FILE_APPEND);
}

$stringFile = $stringsDir.'/settings-choices.php';
file_put_contents($stringFile, "<?php\r\n", FILE_APPEND);
$query = 'select cfg_data as choices, "" as translation, "config_cfg" as cntx from config_cfg
WHERE cfg_type = "choice";';
foreach ($db->query($query) as $row) {
foreach (json_decode($row['choices'])->Choices as $choice) {
file_put_contents($stringFile, 'gettext("'.addslashes($choice)."\");\r\n", FILE_APPEND);
}
}
file_put_contents($stringFile, "\r\n?>", FILE_APPEND);

$stringFile = $stringsDir.'/settings-countries.php';
require '../src/ChurchCRM/data/Countries.php';
file_put_contents($stringFile, "<?php\r\n", FILE_APPEND);
Expand Down
8 changes: 0 additions & 8 deletions propel/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,6 @@
<column name="cfg_id" phpName="Id" type="INTEGER" primaryKey="true" required="true" defaultValue="0"/>
<column name="cfg_name" phpName="Name" type="VARCHAR" size="50" required="true" defaultValue=""/>
<column name="cfg_value" phpName="Value" type="LONGVARCHAR"/>
<column name="cfg_type" phpName="Type" type="CHAR" sqlType="enum('text','number','date','boolean','textarea')"
required="true" defaultValue="text"/>
<column name="cfg_default" phpName="Default" type="LONGVARCHAR" required="true"/>
<column name="cfg_tooltip" phpName="Tooltip" type="LONGVARCHAR" required="true"/>
<column name="cfg_section" phpName="Section" type="VARCHAR" size="50" required="true" defaultValue=""/>
<column name="cfg_category" phpName="Category" type="VARCHAR" size="20"/>
<column name="cfg_order" phpName="Order" type="INTEGER"/>
<column name="cfg_data" phpName="Data" type="LONGVARCHAR"/>
<index name="cfg_id">
<index-column name="cfg_id"/>
</index>
Expand Down
2 changes: 0 additions & 2 deletions src/ChurchCRM/Service/SystemService.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public function restoreDatabaseFromBackup($file)
FileSystemUtils::recursiveRemoveDirectory($restoreResult->backupRoot);
$restoreResult->UpgradeStatus = $this->upgradeDatabaseVersion();
SQLUtils::sqlImport(SystemURLs::getDocumentRoot() . '/mysql/upgrade/rebuild_nav_menus.sql', $connection);
SQLUtils::sqlImport(SystemURLs::getDocumentRoot() . '/mysql/upgrade/update_config.sql', $connection);
//When restoring a database, do NOT let the database continue to create remote backups.
//This can be very troublesome for users in a testing environment.
SystemConfig::setValue('sEnableExternalBackupTarget', '0');
Expand Down Expand Up @@ -320,7 +319,6 @@ public function upgradeDatabaseVersion()
}
// always rebuild the menu
SQLUtils::sqlImport(SystemURLs::getDocumentRoot() . '/mysql/upgrade/rebuild_nav_menus.sql', $connection);
SQLUtils::sqlImport(SystemURLs::getDocumentRoot() . '/mysql/upgrade/update_config.sql', $connection);

return 'success';
}
Expand Down
115 changes: 115 additions & 0 deletions src/ChurchCRM/dto/ConfigItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php
namespace ChurchCRM\dto;

use ChurchCRM\Config;

class ConfigItem
{
private static $id, $name, $value, $type, $default, $tooltip, $data, $dbConfigItem;
public function __construct($id, $name, $type, $default, $tooltip, $data) {
$this->id = $id;
$this->name = $name;
$this->type = $type;
$this->default = $default;
$this->tooltip = $tooltip;
$this->data = $data;
}

public function getId()
{
return $this->id;
}

public function getName()
{
return $this->name;
}

public function setDBConfigObject($dbConfigItem)
{
$this->dbConfigItem = $dbConfigItem;
$this->value = $dbConfigItem->getValue();
}

public function getDBConfigObject()
{
return $this->dbConfigItem ;
}

public function getValue()
{
if ( isset( $this->value ) )
{
return $this->value;
}
else
{
return $this->default;
}
}

public function getBooleanValue()
{
return boolval($this->getValue());
}

public function setValue($value)
{
if ( $value == $this->getDefault() )
{
//if the value is being set to the default value
if ( isset ($this->dbConfigItem) ) //and the item exists
{
//delete the item
$this->dbConfigItem->delete();
}
}
else
{
//if the value is being set to a non-default value
if ( ! isset ($this->dbConfigItem) )
{
//create the item if it doesnt exist
$this->dbConfigItem = new Config();
$this->dbConfigItem->setId($this->getId());
$this->dbConfigItem->setName($this->getName());
}
//set the values, and seve it
$this->dbConfigItem->setValue($value);
$this->dbConfigItem->save();
$this->value=$value;
}
}

public function getDefault()
{
return $this->default;
}


public function getType()
{
return $this->type;
}

public function getTooltip()
{
return $this->tooltip;
}

public function getSection()
{
return $this->section;
}

public function getCategory()
{
return $this->category;
}

public function getData()
{
return $this->data;
}

}
Loading

0 comments on commit ef1e054

Please sign in to comment.