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

Dev: import optimization and cleanup #5596

Merged
merged 5 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions src/ChurchCRM/Service/SystemService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,15 @@

namespace ChurchCRM\Service;

use ChurchCRM\Backup\BackupJob;
use ChurchCRM\Backup\BackupType;
use ChurchCRM\dto\SystemConfig;
use ChurchCRM\dto\SystemURLs;
use ChurchCRM\FileSystemUtils;
use ChurchCRM\SQLUtils;
use ChurchCRM\VersionQuery;
use Exception;
use Ifsnop\Mysqldump\Mysqldump;
use PharData;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\Propel;
use PDO;
use ChurchCRM\Utils\ChurchCRMReleaseManager;
use ChurchCRM\Utils\InputUtils;
use ChurchCRM\Utils\LoggerUtils;
use ChurchCRM\Utils\ExecutionTime;
use ChurchCRM\Backup\BackupJob;
use ChurchCRM\Backup\BackupType;
use ChurchCRM\Utils\ChurchCRMReleaseManager;
use ChurchCRM\dto\ChurchCRMRelease;
use PDO;
use Propel\Runtime\Propel;

require SystemURLs::getDocumentRoot() . '/vendor/ifsnop/mysqldump-php/src/Ifsnop/Mysqldump/Mysqldump.php';

Expand Down Expand Up @@ -54,8 +45,13 @@ public function setConfigurationSetting($settingName, $settingValue)

static public function getDBVersion()
{
$version = VersionQuery::create()->orderByVersion(Criteria::DESC)->findOne();
return $version->getVersion();
$connection = Propel::getConnection();
$query = 'Select * from version_ver';
$statement = $connection->prepare($query);
$statement->execute();
$results = $statement->fetchAll(\PDO::FETCH_ASSOC);
rsort($results);
return $results[0]['ver_version'];
}

public static function getDBServerVersion()
Expand All @@ -69,6 +65,11 @@ public static function getDBServerVersion()
}
}

static public function isDBCurrent()
{
return SystemService::getDBVersion() == SystemService::getInstalledVersion();
}

static public function getDBTableExists($tableName) {
if (!isset($_SESSION['CRM_DB_TABLES']))
{
Expand Down
14 changes: 5 additions & 9 deletions src/ChurchCRM/Slim/Middleware/AuthMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@

namespace ChurchCRM\Slim\Middleware;

use ChurchCRM\UserQuery;
use Slim\Http\Request;
use Slim\Http\Response;
use ChurchCRM\dto\SystemConfig;
use ChurchCRM\Utils\LoggerUtils;
use ChurchCRM\Authentication\AuthenticationManager;
use ChurchCRM\Authentication\Requests\APITokenAuthenticationRequest;
use ChurchCRM\Authentication\AuthenticationProviders\APITokenAuthentication;
use Slim\Http\Request;
use Slim\Http\Response;

class AuthMiddleware {

Expand All @@ -18,18 +14,18 @@ public function __invoke( Request $request, Response $response, callable $next )
if (!$this->isPath( $request, "public")) {
$apiKey = $request->getHeader("x-api-key");
if (!empty($apiKey)) {

$authenticationResult = AuthenticationManager::Authenticate(new APITokenAuthenticationRequest($apiKey[0]));
if (! $authenticationResult->isAuthenticated) {
AuthenticationManager::EndSession(true);
return $response->withStatus(401, gettext('No logged in user'));
}
}
}
// validate the user session; however, do not update tLastOperation if the requested path is "/background"
// since /background operations do not connotate user activity.
else if (AuthenticationManager::ValidateUserSessionIsActive(!$this->isPath( $request, "background"))) {
// User with an active browser session is still authenticated.
// don't really need to do anything here...
// don't really need to do anything here...
}
else {
return $response->withStatus(401, gettext('No logged in user'));
Expand Down
12 changes: 3 additions & 9 deletions src/ChurchCRM/Slim/Middleware/EventsMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,19 @@

namespace ChurchCRM\Slim\Middleware;

use ChurchCRM\EventQuery;
use Slim\Http\Request;
use Slim\Http\Response;
use ChurchCRM\dto\SystemConfig;
use ChurchCRM\Calendar;
use DateTime;
use ChurchCRM\Utils\InputUtils;
use Propel\Runtime\ActiveQuery\Criteria;
use ChurchCRM\EventQuery;
use ChurchCRM\Map\EventTableMap;

class EventsMiddleware
{
public function __invoke(Request $request, Response $response, callable $next)
{
{
$eventId = $request->getAttribute("route")->getArgument("id");
if (empty(trim($eventId))) {
return $response->withStatus(400)->withJson(["message" => gettext("Missing event id")]);
}

$event = EventQuery::Create()
->findPk($eventId);

Expand Down
2 changes: 1 addition & 1 deletion src/ChurchCRM/Slim/Middleware/MailChimpMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace ChurchCRM\Slim\Middleware;

use ChurchCRM\Service\MailChimpService;
use Slim\Http\Request;
use Slim\Http\Response;
use ChurchCRM\Service\MailChimpService;

class MailChimpMiddleware {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace ChurchCRM\Slim\Middleware\Request;

use ChurchCRM\FamilyQuery;
use Slim\Http\Request;
use Slim\Http\Response;
use ChurchCRM\FamilyQuery;

class FamilyAPIMiddleware
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace ChurchCRM\Slim\Middleware\Request;

use ChurchCRM\GroupQuery;
use Slim\Http\Request;
use Slim\Http\Response;
use ChurchCRM\GroupQuery;

class GroupAPIMiddleware
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace ChurchCRM\Slim\Middleware\Request;

use ChurchCRM\PersonQuery;
use Slim\Http\Request;
use Slim\Http\Response;
use ChurchCRM\PersonQuery;

class PersonAPIMiddleware
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace ChurchCRM\Slim\Middleware\Request;

use Slim\Http\Request;
use Slim\Http\Response;
use ChurchCRM\PropertyQuery;
use ChurchCRM\Utils\LoggerUtils;
use Slim\Http\Request;
use Slim\Http\Response;

class PropertyAPIMiddleware
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

namespace ChurchCRM\Slim\Middleware\Request;

use Slim\Http\Request;
use Slim\Http\Response;
use ChurchCRM\dto\SystemConfig;
use ChurchCRM\CalendarQuery;
use ChurchCRM\Calendar;
use DateTime;
use ChurchCRM\Utils\InputUtils;
use Propel\Runtime\ActiveQuery\Criteria;
use ChurchCRM\CalendarQuery;
use ChurchCRM\dto\SystemConfig;
use ChurchCRM\EventQuery;
use ChurchCRM\Map\EventTableMap;
use ChurchCRM\Utils\InputUtils;
use DateTime;
use Propel\Runtime\ActiveQuery\Criteria;
use Slim\Http\Request;
use Slim\Http\Response;

class PublicCalendarAPIMiddleware
{
Expand All @@ -20,12 +20,12 @@ public function __invoke(Request $request, Response $response, callable $next)
if (!SystemConfig::getBooleanValue("bEnableExternalCalendarAPI")) {
return $response->withStatus(403, gettext("External Calendar API is disabled"));
}

$CAT = $request->getAttribute("route")->getArgument("CalendarAccessToken");
if (empty(trim($CAT))) {
return $response->withStatus(400)->withJson(["message" => gettext("Missing calendar access token")]);
}

$calendar = CalendarQuery::create()
->filterByAccessToken($CAT)
->findOne();
Expand All @@ -38,7 +38,7 @@ public function __invoke(Request $request, Response $response, callable $next)
$request = $request->withAttribute("events", $events);
return $next($request, $response);
}

private function getEvents(Request $request, Calendar $calendar)
{
$params = $request->getQueryParams();
Expand All @@ -48,7 +48,7 @@ private function getEvents(Request $request, Calendar $calendar)
$start_date = new DateTime();
}
$start_date->setTime(0, 0, 0);

$events = EventQuery::create()
->joinCalendarEvent()
->useCalendarEventQuery()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace ChurchCRM\Slim\Middleware\Request\Setting;

use ChurchCRM\dto\SystemConfig;
use Slim\Http\Request;
use Slim\Http\Response;
use ChurchCRM\dto\SystemConfig;

abstract class BaseAuthSettingMiddleware
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace ChurchCRM\Slim\Middleware\Request;

use ChurchCRM\Authentication\AuthenticationManager;
use ChurchCRM\UserQuery;
use Slim\Http\Request;
use Slim\Http\Response;
use ChurchCRM\UserQuery;

class UserAPIMiddleware
{
Expand Down
4 changes: 2 additions & 2 deletions src/ChurchCRM/Slim/Middleware/VersionMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace ChurchCRM\Slim\Middleware;

use ChurchCRM\Service\SystemService;
use Slim\Http\Request;
use Slim\Http\Response;
use ChurchCRM\Service\SystemService;

class VersionMiddleware {

public function __invoke( Request $request, Response $response, callable $next )
{
return $next( $request, $response )->withHeader( "CRM_VERSION", SystemService::getInstalledVersion());
}
}
}
2 changes: 0 additions & 2 deletions src/ChurchCRM/data/Countries.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php
namespace ChurchCRM\data;
use ChurchCRM\data\Country;
use Yasumi\Provider;

class Countries
{
Expand Down
Loading