Skip to content

Commit

Permalink
Update for PHP 8.3 and Phalcon 5.8
Browse files Browse the repository at this point in the history
Improve error handling
  • Loading branch information
jorikfon committed Oct 3, 2024
1 parent 37d4fc1 commit a4bcfc0
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/Common/Models/CallDetailRecordsTmp.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

namespace MikoPBX\Common\Models;

use MikoPBX\Common\Handlers\CriticalErrorsHandler;
use MikoPBX\Common\Providers\ManagedCacheProvider;
use MikoPBX\Core\System\SystemMessages;
use Throwable;
Expand Down Expand Up @@ -121,7 +122,7 @@ private function saveCdrCache(bool $isSave = true): void
$managedCache->delete('Workers:Cdr:' . $rowData['UNIQUEID']);
}
} catch (Throwable $e) {
SystemMessages::sysLogMsg(self::class, $e->getMessage());
CriticalErrorsHandler::handleExceptionWithSyslog($e);
return;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Core/Asterisk/Configs/SIPConf.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
Sip,
SipHosts,
Users};
use MikoPBX\Common\Handlers\CriticalErrorsHandler;
use MikoPBX\Common\Providers\PBXConfModulesProvider;
use MikoPBX\Common\Providers\RegistryProvider;
use MikoPBX\Core\Asterisk\AstDB;
Expand Down Expand Up @@ -171,7 +172,7 @@ private function getTopologyData(): array
try {
$sub = new SubnetCalculator($lan_config['ipaddr'], $lan_config['subnet']);
} catch (Throwable $e) {
SystemMessages::sysLogMsg(self::class, $e->getMessage(), LOG_ERR);
CriticalErrorsHandler::handleExceptionWithSyslog($e);
continue;
}
$net = $sub->getNetworkPortion() . '/' . $lan_config['subnet'];
Expand Down
3 changes: 2 additions & 1 deletion src/Core/System/Notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

namespace MikoPBX\Core\System;

use MikoPBX\Common\Handlers\CriticalErrorsHandler;
use MikoPBX\Common\Models\PbxSettings;
use MikoPBX\Common\Providers\ManagedCacheProvider;
use Phalcon\Di\Di;
Expand Down Expand Up @@ -188,7 +189,7 @@ public function sendMail(array|string $to, string $subject, string $message, str
$messages[] = $mail->ErrorInfo;
}
} catch (Throwable $e) {
$messages[] = $e->getMessage();
$messages[] = CriticalErrorsHandler::handleExceptionWithSyslog($e);
}
if (!empty($messages)) {
SystemMessages::sysLogMsg('PHPMailer', implode(' ', $messages), LOG_ERR);
Expand Down
2 changes: 1 addition & 1 deletion src/Core/System/Upgrade/UpdateDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public function createUpdateDbTableByAnnotations(string $modelClassName): bool

// Create additional indexes
$modelClassAnnotation = $modelAnnotation->getClassAnnotations();
if ($modelClassAnnotation !== false
if ($modelClassAnnotation !== null
&& $modelClassAnnotation->has('Indexes')) {
$additionalIndexes = $modelClassAnnotation->get('Indexes')->getArguments();
foreach ($additionalIndexes as $index) {
Expand Down
2 changes: 2 additions & 0 deletions src/Core/System/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Exception;
use MikoPBX\Common\Models\{CustomFiles};
use malkusch\lock\mutex\PHPRedisMutex;
use MikoPBX\Common\Handlers\CriticalErrorsHandler;
use MikoPBX\Common\Providers\AmiConnectionCommand;
use MikoPBX\Common\Providers\AmiConnectionListener;
use MikoPBX\Common\Providers\LanguageProvider;
Expand Down Expand Up @@ -157,6 +158,7 @@ public static function generateRandomString(int $length = 10): string
try {
$randomString .= $characters[random_int(0, $charactersLength - 1)];
} catch (Throwable $e) {
CriticalErrorsHandler::handleExceptionWithSyslog($e);
$randomString = '';
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/Core/Workers/Libs/WorkerCallEvents/SelectCDR.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

namespace MikoPBX\Core\Workers\Libs\WorkerCallEvents;

use MikoPBX\Common\Handlers\CriticalErrorsHandler;
use MikoPBX\Common\Models\CallDetailRecords;
use MikoPBX\Common\Models\CallDetailRecordsTmp;
use MikoPBX\Core\System\Util;
Expand Down Expand Up @@ -57,6 +58,7 @@ public static function execute(array $filter): string
}
$res_data = json_encode($res->toArray());
} catch (Throwable $e) {
CriticalErrorsHandler::handleExceptionWithSyslog($e);
$res_data = '[]';
}

Expand All @@ -75,6 +77,7 @@ public static function execute(array $filter): string
$res = CallDetailRecords::find($filter['add_pack_query']);
$res_data = json_encode($res->toArray(), JSON_THROW_ON_ERROR);
} catch (Throwable $e) {
CriticalErrorsHandler::handleExceptionWithSyslog($e);
$res_data = '[]';
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/Core/Workers/WorkerCallEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
require_once 'Globals.php';

use MikoPBX\Core\System\{BeanstalkClient, Directories, SystemMessages, Util};
use MikoPBX\Common\Handlers\CriticalErrorsHandler;
use MikoPBX\Common\Models\Extensions;
use MikoPBX\Common\Models\PbxSettings;
use MikoPBX\Common\Models\Sip;
Expand Down Expand Up @@ -410,6 +411,7 @@ public function callEventsWorker(BeanstalkClient $tube): void
JSON_THROW_ON_ERROR
);
} catch (Throwable $e) {
CriticalErrorsHandler::handleExceptionWithSyslog($e);
$data = [];
}

Expand Down
3 changes: 2 additions & 1 deletion src/Modules/Setup/PbxExtensionSetupBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

namespace MikoPBX\Modules\Setup;

use MikoPBX\Common\Handlers\CriticalErrorsHandler;
use MikoPBX\Common\Providers\ModulesDBConnectionsProvider;
use MikoPBX\Common\Providers\PBXConfModulesProvider;
use MikoPBX\Core\System\Processes;
Expand Down Expand Up @@ -213,7 +214,7 @@ public function installModule(): bool
PBXConfModulesProvider::getVersionsHash(true);

} catch (Throwable $exception) {
$this->messages[] = $exception->getMessage();
$this->messages[] = CriticalErrorsHandler::handleExceptionWithSyslog($exception);
return false;
}

Expand Down

0 comments on commit a4bcfc0

Please sign in to comment.