Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

throw http exceptions when possible, try to pass around arrays instead of stringified arrays #6752

Merged
merged 7 commits into from
Dec 15, 2023
Merged
27 changes: 16 additions & 11 deletions locale/extract-db-locale-terms.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<?php

echo "=============================================== \n";
echo "========== Building locale from DB started === \n";
echo "=============================================== \n\n";
echo <<<HEREDOC
===============================================
========== Building locale from DB started ===
===============================================

HEREDOC;

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

if (file_exists($filename)) {
if (is_file($filename)) {
$buildConfig = file_get_contents($filename);
$config = json_decode($buildConfig, true);

Expand Down Expand Up @@ -41,10 +44,10 @@
echo "DB read complete \n";

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

$stringFile = $stringsDir.'/settings-countries.php';
$stringFile = $stringsDir.DIRECTORY_SEPARATOR.'settings-countries.php';
require '../src/ChurchCRM/data/Countries.php';
require '../src/ChurchCRM/data/Country.php';
file_put_contents($stringFile, "<?php\r\n", FILE_APPEND);
Expand All @@ -64,9 +67,11 @@
}
file_put_contents($stringFile, "\r\n?>", FILE_APPEND);

$stringFile = $stringsDir.'/settings-locales.php';
$stringFile = $stringsDir.DIRECTORY_SEPARATOR.'settings-locales.php';
file_put_contents($stringFile, "<?php\r\n", FILE_APPEND);
$localesFile = file_get_contents('../src/locale/locales.json');
$localesFile = file_get_contents(
implode(DIRECTORY_SEPARATOR, ['..','src','locale','locales.json'])
);
$locales = json_decode($localesFile, true);
foreach ($locales as $key => $value) {
file_put_contents($stringFile, 'gettext("'.$key."\");\r\n", FILE_APPEND);
Expand Down
2 changes: 1 addition & 1 deletion src/ChurchCRM/Backup/BackupJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private function createFullArchive()
if ($this->shouldBackupImageFile($imageFile)) {
$localName = substr(str_replace(SystemURLs::getDocumentRoot(), '', $imageFile->getRealPath()), 1);
$phar->addFile($imageFile->getRealPath(), $localName);
array_push($imagesAddedToArchive, $imageFile->getRealPath());
$imagesAddedToArchive[] = $imageFile->getRealPath();
}
}
LoggerUtils::getAppLogger()->debug('Images files added to archive: ' . join(';', $imagesAddedToArchive));
Expand Down
2 changes: 1 addition & 1 deletion src/ChurchCRM/Backup/RestoreJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private function postRestoreCleanup()
//This can be very troublesome for users in a testing environment.
LoggerUtils::getAppLogger()->debug('Starting post-restore cleanup');
SystemConfig::setValue('bEnableExternalBackupTarget', '0');
array_push($this->Messages, gettext('As part of the restore, external backups have been disabled. If you wish to continue automatic backups, you must manuall re-enable the bEnableExternalBackupTarget setting.'));
$this->Messages[] = gettext('As part of the restore, external backups have been disabled. If you wish to continue automatic backups, you must manuall re-enable the bEnableExternalBackupTarget setting.');
SystemConfig::setValue('sLastIntegrityCheckTimeStamp', null);
LoggerUtils::getAppLogger()->debug('Reset System Settings for: bEnableExternalBackupTarget and sLastIntegrityCheckTimeStamp');
}
Expand Down
4 changes: 2 additions & 2 deletions src/ChurchCRM/Config/Menu/MenuItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public function addSubMenu(MenuItem $menuItem)
if (empty($menuItem->getIcon())) {
$menuItem->setIcon('fa-angle-double-right');
}
array_push($this->subItems, $menuItem);
$this->subItems[] = $menuItem;
}

public function addCounter(MenuCounter $counter)
{
array_push($this->counters, $counter);
$this->counters[] = $counter;
}

public function getURI()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct($RelatedObject)
if (!empty($Person)) {
$email = $Person->getEmail();
if (!empty($email)) {
array_push($toAddresses, $email);
$toAddresses[] = $email;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ChurchCRM/Search/AddressSearchResultProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private function getPersonSearchResultsByPartialAddress(string $SearchQuery)
if (!empty($addresses)) {
$id++;
foreach ($addresses as $address) {
array_push($searchResults, new SearchResult('person-address-' . $id, $address->getFamilyString(SystemConfig::getBooleanValue('bSearchIncludeFamilyHOH')), $address->getViewURI()));
$searchResults[] = new SearchResult('person-address-' . $id, $address->getFamilyString(SystemConfig::getBooleanValue('bSearchIncludeFamilyHOH')), $address->getViewURI());
}
}
} catch (\Exception $e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private function getCalendarEventSearchResultsByPartialName(string $SearchQuery)
if (!empty($events)) {
$id++;
foreach ($events as $event) {
array_push($searchResults, new SearchResult('event-name-' . $id, $event->getTitle(), $event->getViewURI()));
$searchResults[] = new SearchResult('event-name-' . $id, $event->getTitle(), $event->getViewURI());
}
}
} catch (\Exception $e) {
Expand Down
4 changes: 2 additions & 2 deletions src/ChurchCRM/Search/FamilySearchResultProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private function getFamilySearchResultsByPartialName(string $SearchQuery)
if (!empty($families)) {
$id++;
foreach ($families as $family) {
array_push($searchResults, new SearchResult('family-name-' . $id, $family->getFamilyString(SystemConfig::getBooleanValue('bSearchIncludeFamilyHOH')), $family->getViewURI()));
$searchResults[] = new SearchResult('family-name-' . $id, $family->getFamilyString(SystemConfig::getBooleanValue('bSearchIncludeFamilyHOH')), $family->getViewURI());
}
}

Expand Down Expand Up @@ -74,7 +74,7 @@ private function getFamilySearchResultsByCustomProperties(string $SearchQuery)
$families = $familyQuery->endUse()->find();
foreach ($families as $family) {
$id++;
array_push($searchResults, new SearchResult('family-custom-prop-' . $id, $family->getFamilyString(SystemConfig::getBooleanValue('bSearchIncludeFamilyHOH')), $family->getViewURI()));
$searchResults[] = new SearchResult('family-custom-prop-' . $id, $family->getFamilyString(SystemConfig::getBooleanValue('bSearchIncludeFamilyHOH')), $family->getViewURI());
}
} catch (\Exception $e) {
LoggerUtils::getAppLogger()->warning($e->getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private function getDepositSearchResults(string $SearchQuery)
if (!empty($Deposits)) {
$id++;
foreach ($Deposits->toArray() as $Deposit) {
array_push($searchResults, new SearchResult('finance-deposit-' . $id, $Deposit['displayName'], $Deposit['uri']));
$searchResults[] = new SearchResult('finance-deposit-' . $id, $Deposit['displayName'], $Deposit['uri']);
}
}
} catch (\Exception $e) {
Expand Down
4 changes: 2 additions & 2 deletions src/ChurchCRM/Search/FinancePaymentSearchResultProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private function getPaymentsWithValuesInRange(int $min, int $max)
// I can't seem to get the SQL HAVING clause to work through Propel ORM to use
// both MIN and MAX value. Just filter it in PHP
if ($Payment->getVirtualColumn('GroupAmount') >= $min && $Payment->getVirtualColumn('GroupAmount') <= $max) {
array_push($searchResults, new SearchResult('finance-payment-' . $id, '$' . $Payment->getVirtualColumn('GroupAmount') . ' Payment on Deposit ' . $Payment->getDepid(), $Payment->getVirtualColumn('uri')));
$searchResults[] = new SearchResult('finance-payment-' . $id, '$' . $Payment->getVirtualColumn('GroupAmount') . ' Payment on Deposit ' . $Payment->getDepid(), $Payment->getVirtualColumn('uri'));
}
}
}
Expand Down Expand Up @@ -83,7 +83,7 @@ private function getPaymentSearchResults(string $SearchQuery)
if (!empty($Payments)) {
$id++;
foreach ($Payments as $Payment) {
array_push($searchResults, new SearchResult('finance-payment-' . $id, 'Check ' . $Payment->getCheckNo() . ' on Deposit ' . $Payment->getDepId(), $Payment->getVirtualColumn('uri')));
$searchResults[] = new SearchResult('finance-payment-' . $id, 'Check ' . $Payment->getCheckNo() . ' on Deposit ' . $Payment->getDepId(), $Payment->getVirtualColumn('uri'));
}
}
} catch (\Exception $e) {
Expand Down
2 changes: 1 addition & 1 deletion src/ChurchCRM/Search/GroupSearchResultProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private function getPersonSearchResultsByPartialName(string $SearchQuery)
if (!empty($groups)) {
$id++;
foreach ($groups as $group) {
array_push($searchResults, new SearchResult('group-name-' . $id, $group->getName(), $group->getViewURI()));
$searchResults[] = new SearchResult('group-name-' . $id, $group->getName(), $group->getViewURI());
}
}
} catch (\Exception $e) {
Expand Down
2 changes: 1 addition & 1 deletion src/ChurchCRM/Search/PersonSearchResultProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private function getPersonSearchResultsByPartialName(string $SearchQuery)
if (!empty($people)) {
$id++;
foreach ($people as $person) {
array_push($searchResults, new SearchResult('person-name-' . $id, $person->getFullName(), $person->getViewURI()));
$searchResults[] = new SearchResult('person-name-' . $id, $person->getFullName(), $person->getViewURI());
}
}
} catch (\Exception $e) {
Expand Down
16 changes: 8 additions & 8 deletions src/ChurchCRM/Service/AppIntegrityService.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,19 @@ public static function verifyApplicationIntegrity(): array
$actualHash = sha1_file($currentFile);
if ($actualHash != $file->sha1) {
$logger->warning('File hash mismatch: ' . $file->filename . '. Expected: ' . $file->sha1 . '; Got: ' . $actualHash);
array_push($signatureFailures, [
'filename' => $file->filename,
'status' => 'Hash Mismatch',
$signatureFailures[] = [
'filename' => $file->filename,
'status' => 'Hash Mismatch',
'expectedhash' => $file->sha1,
'actualhash' => $actualHash,
]);
'actualhash' => $actualHash,
];
}
} else {
$logger->warning('File Missing: ' . $file->filename);
array_push($signatureFailures, [
$signatureFailures[] = [
'filename' => $file->filename,
'status' => 'File Missing',
]);
'status' => 'File Missing',
];
}
}
} else {
Expand Down
13 changes: 6 additions & 7 deletions src/ChurchCRM/Service/FinancialService.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function getPayments($depID = null)
$values->plg_NonDeductible = $plg_NonDeductible;
$values->plg_GroupKey = $plg_GroupKey;

array_push($payments, $values);
$payments[] = $values;
}

return $payments;
Expand Down Expand Up @@ -329,7 +329,7 @@ public function getPledgeorPayment($GroupKey)
$fund['Amount'] = $plg_amount;
$fund['NonDeductible'] = $plg_NonDeductible;
$fund['Comment'] = $plg_comment;
array_push($payment->funds, $fund);
$payment->funds[] = $fund;
$total += $plg_amount;
$onePlgID = $aRow['plg_plgID'];
$oneFundID = $aRow['plg_fundID'];
Expand Down Expand Up @@ -551,14 +551,13 @@ public function getDepositCSV($depID)
throw new \Exception('No Payments on this Deposit', 404);
}
foreach ($payments[0] as $key => $value) {
array_push($line, $key);
$line[] = $key;
}
$retstring = implode(',', $line) . "\n";
$line = [];
foreach ($payments as $payment) {
$line = [];
foreach ($payment as $key => $value) {
array_push($line, str_replace(',', '', $value));
$line[] = str_replace(',', '', $value);
}
$retstring .= implode(',', $line) . "\n";
}
Expand Down Expand Up @@ -597,7 +596,7 @@ public function getCurrency()
$currency->Name = $row['cdem_denominationName'];
$currency->Value = $row['cdem_denominationValue'];
$currency->cClass = $row['cdem_denominationClass'];
array_push($currencies, $currency);
$currencies[] = $currency;
} // end while

return $currencies;
Expand All @@ -616,7 +615,7 @@ public function getActiveFunds()
$fund->ID = $aRow['fun_ID'];
$fund->Name = $aRow['fun_Name'];
$fund->Description = $aRow['fun_Description'];
array_push($funds, $fund);
$funds[] = $fund;
} // end while

return $funds;
Expand Down
4 changes: 2 additions & 2 deletions src/ChurchCRM/Service/GroupService.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function getGroupRoles($groupID)
}

while ($row = mysqli_fetch_assoc($rsList)) {
array_push($groupRoles, $row);
$groupRoles[] = $row;
}

return $groupRoles;
Expand Down Expand Up @@ -325,7 +325,7 @@ public function getGroupMembers($groupID, $personID = null)
if (array_key_exists('displayName', $dbPerson)) {
$person['displayName'] = $dbPerson->getFullName();
$person['groupRole'] = $row['lst_OptionName'];
array_push($members, $person);
$members[] = $person;
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/ChurchCRM/Service/MailChimpService.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ private function getListsFromCache()
]
);
foreach ($listmembers['members'] as $member) {
array_push($list['members'], [
'email' => strtolower($member['email_address']),
'first' => $member['merge_fields']['FNAME'],
'last' => $member['merge_fields']['LNAME'],
$list['members'][] = [
'email' => strtolower($member['email_address']),
'first' => $member['merge_fields']['FNAME'],
'last' => $member['merge_fields']['LNAME'],
'status' => $member['status'],
]);
];
}
LoggerUtils::getAppLogger()->debug('MailChimp list ' . $list['id'] . ' membership ' . count($list['members']));
}
Expand Down Expand Up @@ -90,7 +90,7 @@ public function isEmailInMailChimp($email)
foreach ($lists as $list) {
$data = $this->myMailchimp->get('lists/' . $list['id'] . '/members/' . md5($email));
LoggerUtils::getAppLogger()->debug($email . ' is ' . $data['status'] . ' to ' . $list['name']);
array_push($listsStatus, ['name' => $list['name'], 'status' => $data['status'], 'stats' => $data['stats']]);
$listsStatus[] = ['name' => $list['name'], 'status' => $data['status'], 'stats' => $data['stats']];
}

return $listsStatus;
Expand Down
2 changes: 1 addition & 1 deletion src/ChurchCRM/Service/NewDashboardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function getDashboardItems($PageName)
$ReturnValues = [];
foreach ($DashboardItems as $DashboardItem) {
if ($DashboardItem::shouldInclude($PageName)) {
array_push($ReturnValues, $DashboardItem);
$ReturnValues[] = $DashboardItem;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ChurchCRM/Service/NotificationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static function getNotifications(): array
foreach ($_SESSION['SystemNotifications']->messages as $message) {
if ($message->targetVersion === $_SESSION['sSoftwareInstalledVersion']) {
if (!$message->adminOnly || AuthenticationManager::getCurrentUser()->isAdmin()) {
array_push($notifications, $message);
$notifications[] = $message;
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/ChurchCRM/Service/PersonService.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function search($searchTerm, $includeFamilyRole = true)
}
$values['familyRole'] = $familyRole;
}
array_push($return, $values);
$return[] = $values;
}

return $return;
Expand Down Expand Up @@ -72,7 +72,7 @@ public function getPeopleEmailsAndGroups()
while ($row = mysqli_fetch_array($rsPeopleWithEmails)) {
if ($lastPersonId != $row['per_ID']) {
if ($lastPersonId != 0) {
array_push($people, $person);
$people[] = $person;
}
$person = [];
$person['id'] = $row['per_ID'];
Expand All @@ -87,7 +87,7 @@ public function getPeopleEmailsAndGroups()
$lastPersonId = $row['per_ID'];
}
}
array_push($people, $person);
$people[] = $person;

return $people;
}
Expand Down
Loading
Loading