Skip to content

Commit

Permalink
Apply fixes from StyleCI
Browse files Browse the repository at this point in the history
  • Loading branch information
DAcodedBEAT authored and StyleCIBot committed Dec 19, 2024
1 parent 68559c0 commit 86fa36a
Show file tree
Hide file tree
Showing 293 changed files with 7,962 additions and 7,817 deletions.
7 changes: 3 additions & 4 deletions docker/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
$sUSER = 'churchcrm';
$sPASSWORD = 'changeme';
$sDATABASE = 'churchcrm';
#$TwoFASecretKey = 'ChangeThisToASecureRandomStringBeforeUse';
//$TwoFASecretKey = 'ChangeThisToASecureRandomStringBeforeUse';

// Root path of your ChurchCRM installation ( THIS MUST BE SET CORRECTLY! )
//
Expand All @@ -29,7 +29,7 @@

// Set $bLockURL=TRUE to enforce https access by specifying exactly
// which URL's your users may use to log into ChurchCRM.
$bLockURL = FALSE;
$bLockURL = false;

// URL[0] is the URL that you prefer most users use when they
// log in. These are case sensitive.
Expand Down Expand Up @@ -60,5 +60,4 @@
//
// Absolute path must be specified since this file is called
// from scripts located in other directories
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'LoadConfigs.php');
?>
require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'LoadConfigs.php';
36 changes: 17 additions & 19 deletions locale/extract-db-locale-terms.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,28 @@
echo "========== Building locale from DB started === \n";
echo "=============================================== \n\n";

$filename = "../BuildConfig.json";
$filename = '../BuildConfig.json';

if (file_exists($filename)) {

$buildConfig = file_get_contents($filename);
$config = json_decode($buildConfig, true);

if (empty($config["Env"]["local"]["database"])) {
if (empty($config['Env']['local']['database'])) {
echo "ERROR: The file $filename does not have local db env, check ".$filename.".example for schema\n";
} else {
$localDBEnv = $config["Env"]["local"]["database"];
$localDBEnv = $config['Env']['local']['database'];

$db_server = $localDBEnv["server"];
$db_port = $localDBEnv["port"];
$db_server = $localDBEnv['server'];
$db_port = $localDBEnv['port'];

$db_name = $localDBEnv["database"];
$db_username = $localDBEnv["user"];
$db_password = $localDBEnv["password"];
$db_name = $localDBEnv['database'];
$db_username = $localDBEnv['user'];
$db_password = $localDBEnv['password'];

$stringsDir = 'db-strings';
$stringFiles = [];

$db = new PDO('mysql:host=' . $db_server . ':' . $db_port . ';dbname=' . $db_name . ';charset=utf8mb4', $db_username, $db_password);
$db = new PDO('mysql:host='.$db_server.':'.$db_port.';dbname='.$db_name.';charset=utf8mb4', $db_username, $db_password);
$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
Expand All @@ -42,42 +41,41 @@
echo "DB read complete \n";

foreach ($db->query($query) as $row) {
$stringFile = $stringsDir . '/' . $row['cntx'] . '.php';
$stringFile = $stringsDir.'/'.$row['cntx'].'.php';
if (!file_exists($stringFile)) {
file_put_contents($stringFile, "<?php\r\n", FILE_APPEND);
array_push($stringFiles, $stringFile);
}
$rawDBTerm = $row['term'];
$dbTerm = addslashes($rawDBTerm);
file_put_contents($stringFile, "gettext('" . $dbTerm . "');\n", FILE_APPEND);
file_put_contents($stringFile, "gettext('".$dbTerm."');\n", FILE_APPEND);
}
foreach ($stringFiles as $stringFile) {
file_put_contents($stringFile, "\r\n?>", FILE_APPEND);
}

$stringFile = $stringsDir . '/settings-countries.php';
$stringFile = $stringsDir.'/settings-countries.php';
require '../src/ChurchCRM/data/Countries.php';
require '../src/ChurchCRM/data/Country.php';
file_put_contents($stringFile, "<?php\r\n", FILE_APPEND);

foreach (ChurchCRM\data\Countries::getNames() as $country) {
file_put_contents($stringFile, 'gettext("' . addslashes($country) . "\");\r\n", FILE_APPEND);
file_put_contents($stringFile, 'gettext("'.addslashes($country)."\");\r\n", FILE_APPEND);
}
file_put_contents($stringFile, "\r\n?>", FILE_APPEND);

$stringFile = $stringsDir . '/settings-locales.php';
$stringFile = $stringsDir.'/settings-locales.php';
file_put_contents($stringFile, "<?php\r\n", FILE_APPEND);
$localesFile = file_get_contents("../src/locale/locales.json");
$localesFile = file_get_contents('../src/locale/locales.json');
$locales = json_decode($localesFile, true);
foreach ($locales as $key => $value) {
file_put_contents($stringFile, 'gettext("' . $key . "\");\r\n", FILE_APPEND);
file_put_contents($stringFile, 'gettext("'.$key."\");\r\n", FILE_APPEND);
}
file_put_contents($stringFile, "\r\n?>", FILE_APPEND);
echo $stringFile . " updated";
echo $stringFile.' updated';
}
} else {
echo "ERROR: The file $filename does not exist \n";

}
echo "\n\n=============================================== \n";
echo "========== Building locale from DB end === \n";
Expand Down
116 changes: 55 additions & 61 deletions scripts/restore-db.php
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
<?php

include dirname(__FILE__)."/../src/ChurchCRM/SQLUtils.php";
Use ChurchCRM\SQLUtils;
include dirname(__FILE__).'/../src/ChurchCRM/SQLUtils.php';
use ChurchCRM\SQLUtils;

$sSERVERNAME = "";
$sUSER = "";
$sPASSWORD = "";
$sDATABASE = "";
$dbPort = "";
$restoreDemoDb = $argv[1] == "demo";
$sSERVERNAME = '';
$sUSER = '';
$sPASSWORD = '';
$sDATABASE = '';
$dbPort = '';
$restoreDemoDb = $argv[1] == 'demo';

function extract_config_values($value){
function extract_config_values($value)
{
global $sSERVERNAME,$sUSER,$sPASSWORD,$sDATABASE,$dbPort;

global $sSERVERNAME,$sUSER,$sPASSWORD,$sDATABASE,$dbPort;
if (preg_match('/\\$sSERVERNAME\\s+=\\s+[\'"](.*?)[\'"];/', $value, $matches)) {
$sSERVERNAME = $matches[1];
}

if (preg_match('/\\$sSERVERNAME\\s+=\\s+[\'"](.*?)[\'"];/',$value,$matches)) {
$sSERVERNAME = $matches[1];
}
if (preg_match('/\\$sUSER\\s+=\\s+[\'"](.*?)[\'"];/', $value, $matches)) {
$sUSER = $matches[1];
}

if (preg_match('/\\$sUSER\\s+=\\s+[\'"](.*?)[\'"];/',$value,$matches)) {
$sUSER = $matches[1];
}
if (preg_match('/\\$sPASSWORD\\s+=\\s+[\'"](.*?)[\'"];/', $value, $matches)) {
$sPASSWORD = $matches[1];
}

if (preg_match('/\\$sPASSWORD\\s+=\\s+[\'"](.*?)[\'"];/',$value,$matches)) {
$sPASSWORD = $matches[1];
}
if (preg_match('/\\$sDATABASE\\s+=\\s+[\'"](.*?)[\'"];/', $value, $matches)) {
$sDATABASE = $matches[1];
}

if (preg_match('/\\$sDATABASE\\s+=\\s+[\'"](.*?)[\'"];/',$value,$matches)) {
$sDATABASE = $matches[1];
}

if (preg_match('/\\$dbPort\\s+=\\s+[\'"](.*?)[\'"];/',$value,$matches)) {
$dbPort = $matches[1];
}
if (preg_match('/\\$dbPort\\s+=\\s+[\'"](.*?)[\'"];/', $value, $matches)) {
$dbPort = $matches[1];
}
}

$config = explode("\n",file_get_contents (dirname(__FILE__)."/../src/Include/Config.php"));
array_map("extract_config_values",$config);
$config = explode("\n", file_get_contents(dirname(__FILE__).'/../src/Include/Config.php'));
array_map('extract_config_values', $config);

echo "Beginning to restore demo database\n";
echo "MySQL Server: $sSERVERNAME\n";
Expand All @@ -46,38 +46,32 @@ function extract_config_values($value){
echo "Database: $sDATABASE\n";

try {
$mysqli = new mysqli($sSERVERNAME, $sUSER, $sPASSWORD, $sDATABASE,$dbPort);
if (mysqli_connect_errno())
{
throw new \Exception("Failed to connect to MySQL: " . mysqli_connect_error());
}
$mysqli->select_db($sDATABASE);
echo "Connected to database\n";
echo "Deleting all tables\n";
$mysqli = new mysqli($sSERVERNAME, $sUSER, $sPASSWORD, $sDATABASE, $dbPort);
if (mysqli_connect_errno()) {
throw new \Exception('Failed to connect to MySQL: '.mysqli_connect_error());
}
$mysqli->select_db($sDATABASE);
echo "Connected to database\n";
echo "Deleting all tables\n";

if ($result = $mysqli->query("SHOW TABLES"))
{
while($row = $result->fetch_array(MYSQLI_NUM))
{
$mysqli->query('DROP TABLE IF EXISTS '.$row[0]);
}
}
// this is a bit hacky, but anything left in TABLES here must be a view
if ($result = $mysqli->query("SHOW TABLES"))
{
while($row = $result->fetch_array(MYSQLI_NUM))
{
$mysqli->query('DROP VIEW IF EXISTS '.$row[0]);
}
}
$mysqli->query('SET foreign_key_checks = 1');
echo "Tables deleted\n";
if ($restoreDemoDb) {
echo "restoring demo db\n";
SQLUtils::sqlImport(dirname(__FILE__)."/../demo/ChurchCRM-Database.sql", $mysqli);
echo "Demo db restored\n\n";
}
if ($result = $mysqli->query('SHOW TABLES')) {
while ($row = $result->fetch_array(MYSQLI_NUM)) {
$mysqli->query('DROP TABLE IF EXISTS '.$row[0]);
}
}
// this is a bit hacky, but anything left in TABLES here must be a view
if ($result = $mysqli->query('SHOW TABLES')) {
while ($row = $result->fetch_array(MYSQLI_NUM)) {
$mysqli->query('DROP VIEW IF EXISTS '.$row[0]);
}
}
$mysqli->query('SET foreign_key_checks = 1');
echo "Tables deleted\n";
if ($restoreDemoDb) {
echo "restoring demo db\n";
SQLUtils::sqlImport(dirname(__FILE__).'/../demo/ChurchCRM-Database.sql', $mysqli);
echo "Demo db restored\n\n";
}
} catch (\Exception $e) {
echo "Error restoring database: $e";
}
catch (\Exception $e) {
echo "Error restoring database: $e";
}
57 changes: 30 additions & 27 deletions scripts/update-demo-site.php
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
<?php

function ConsoleWriteLine($string) {
function ConsoleWriteLine($string)
{
echo $string."\n";
}

function GetDemoKey() {
$buildconfigs = \json_decode(file_get_contents("BuildConfig.json"), true);
if (!empty($buildconfigs['demoKey'])){
ConsoleWriteLine("Using demoKey from buildconfig.json");
function GetDemoKey()
{
$buildconfigs = \json_decode(file_get_contents('BuildConfig.json'), true);
if (!empty($buildconfigs['demoKey'])) {
ConsoleWriteLine('Using demoKey from buildconfig.json');

return $buildconfigs['demoKey'];
}
elseif (!empty(getenv('demoKey'))) {
ConsoleWriteLine("Using demoKey from environment variables");
} elseif (!empty(getenv('demoKey'))) {
ConsoleWriteLine('Using demoKey from environment variables');

return getenv('demoKey');
}
else {
throw new \Exception("No demoKey could be found");
} else {
throw new \Exception('No demoKey could be found');
}
}

function GetBranchName() {
if (!empty(getenv("TRAVIS_BRANCH"))) {
return getenv("TRAVIS_BRANCH");
}
else {
return exec("git rev-parse --abbrev-ref HEAD");
function GetBranchName()
{
if (!empty(getenv('TRAVIS_BRANCH'))) {
return getenv('TRAVIS_BRANCH');
} else {
return exec('git rev-parse --abbrev-ref HEAD');
}
}

$buildVersion = $buildconfigs = \json_decode(file_get_contents("package.json"), true)['version'];
$uploadFile = "target/ChurchCRM-".$buildVersion.".zip";
$buildVersion = $buildconfigs = \json_decode(file_get_contents('package.json'), true)['version'];
$uploadFile = 'target/ChurchCRM-'.$buildVersion.'.zip';
$currentBranch = GetBranchName();
$commitHash = exec("git log --pretty=format:%H -n 1");
$commitHash = exec('git log --pretty=format:%H -n 1');

ConsoleWriteLine("Uploading $uploadFile to demosite as $currentBranch with hash: $commitHash");
// initialise the curl request
Expand All @@ -42,17 +44,18 @@ function GetBranchName() {
curl_setopt(
$request,
CURLOPT_POSTFIELDS,
array(
'fileupload' => curl_file_create($uploadFile),
'branch' => $currentBranch,
'commitHash' => $commitHash,
'demoKey' => GetDemoKey()
));
[
'fileupload' => curl_file_create($uploadFile),
'branch' => $currentBranch,
'commitHash' => $commitHash,
'demoKey' => GetDemoKey(),
]
);

// output the response
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($request);
print_r($result);

// close the session
curl_close($request);
curl_close($request);
Loading

0 comments on commit 86fa36a

Please sign in to comment.