diff --git a/core/LogBrokenOrmCaseLog.php b/core/LogBrokenOrmCaseLog.php deleted file mode 100644 index f32e11f55..000000000 --- a/core/LogBrokenOrmCaseLog.php +++ /dev/null @@ -1,15 +0,0 @@ -CheckProfiles(); - } catch (Exception $oException) { - \IssueLog::Error('Broken caselog', LogChannels::ORM_CASELOG, [ - 'caselog_id' => $sCaseLogId, - 'exception_message' => $oException->getMessage(), - 'exception_stacktrace' => $oException->getTraceAsString(), - ]); - } - } -} diff --git a/core/LogBrokenOrmCaseLogExtension.inc.php b/core/ormBrokenCaselogExtension.inc.php similarity index 94% rename from core/LogBrokenOrmCaseLogExtension.inc.php rename to core/ormBrokenCaselogExtension.inc.php index 77e377a41..0452751e3 100644 --- a/core/LogBrokenOrmCaseLogExtension.inc.php +++ b/core/ormBrokenCaselogExtension.inc.php @@ -1,6 +1,6 @@ \w+-\d+-\d+ \d+:\d+:\d+) : (?.*)\s\((?\d+)\) ============\n\n"; @@ -11,10 +11,12 @@ class LogBrokenOrmCaseLogExtension implements iOrmCaseLogExtension { } } catch (Exception $oException) { \IssueLog::Error('Broken caselog', LogChannels::ORM_CASELOG, [ - 'exception_message' => $oException->getMessage(), + 'sLog' => $sLog, + '$aIndex' => $aIndex, 'exception_stacktrace' => $oException->getTraceAsString(), ]); } + return false; } /** diff --git a/lib/composer/autoload_classmap.php b/lib/composer/autoload_classmap.php index b15367dce..43f1a2451 100644 --- a/lib/composer/autoload_classmap.php +++ b/lib/composer/autoload_classmap.php @@ -2970,6 +2970,7 @@ return array( 'lnkAuditCategoryToAuditDomain' => $baseDir . '/application/audit.domain.class.inc.php', 'lnkTriggerAction' => $baseDir . '/core/trigger.class.inc.php', 'ormCaseLog' => $baseDir . '/core/ormcaselog.class.inc.php', + 'ormBrokenCaselogExtension' => $baseDir . '/core/ormBrokenCaselogExtension.inc.php', 'ormCaseLogService' => $baseDir . '/core/ormcaselogservice.inc.php', 'ormCustomFieldsValue' => $baseDir . '/core/ormcustomfieldsvalue.class.inc.php', 'ormDocument' => $baseDir . '/core/ormdocument.class.inc.php', diff --git a/lib/composer/autoload_static.php b/lib/composer/autoload_static.php index 15e466bb4..cd81eb357 100644 --- a/lib/composer/autoload_static.php +++ b/lib/composer/autoload_static.php @@ -3334,6 +3334,7 @@ class ComposerStaticInit7f81b4a2a468a061c306af5e447a9a9f 'iWorkingTimeComputer' => __DIR__ . '/../..' . '/core/computing.inc.php', 'lnkAuditCategoryToAuditDomain' => __DIR__ . '/../..' . '/application/audit.domain.class.inc.php', 'lnkTriggerAction' => __DIR__ . '/../..' . '/core/trigger.class.inc.php', + 'ormBrokenCaselogExtension' => __DIR__ . '/../..' . '/core/ormBrokenCaselogExtension.inc.php', 'ormCaseLog' => __DIR__ . '/../..' . '/core/ormcaselog.class.inc.php', 'ormCaseLogService' => __DIR__ . '/../..' . '/core/ormcaselogservice.inc.php', 'ormCustomFieldsValue' => __DIR__ . '/../..' . '/core/ormcustomfieldsvalue.class.inc.php', diff --git a/tests/php-unit-tests/unitary-tests/core/ormBrokenCaselogExtensionTest.php b/tests/php-unit-tests/unitary-tests/core/ormBrokenCaselogExtensionTest.php new file mode 100644 index 000000000..933f3c64a --- /dev/null +++ b/tests/php-unit-tests/unitary-tests/core/ormBrokenCaselogExtensionTest.php @@ -0,0 +1,80 @@ + 'Administrator'), true); + + if (is_object($oAdminProfile)) { + $this->sLogin = sprintf("admin-%s-%s", date('dmYHis'), uniqid()); + + $this->CreateTestOrganization(); + + /** @var \Person $oPerson */ + $oPerson = $this->createObject('Person', array( + 'name' => $this->sLogin, + 'first_name' => 'Test', + 'org_id' => $this->getTestOrgId(), + )); + + $this->CreateUser($this->sLogin, $oAdminProfile->GetKey(), $this->sPassword, $oPerson->GetKey()); + } + } + + public function LogBrokenCaseLogProvider(){ + return [ + 'extension configured / should log broken caselog info' => [ true ], + 'extension NOT configured/ should do nothing' => [ false ], + ]; + } + + /** + * @dataProvider LogBrokenCaseLogProvider + */ + public function testLogBrokenCaseLog_constructor($bExtensionConfigured){ + if ($bExtensionConfigured){ + \MetaModel::GetConfig()->Set('ormcaselog_extension_classes', [ \ormBrokenCaselogExtension::class]); + } + + $sLog = "aaaaa"; + $aInitialIndex = ['a' => 'b']; + + $sLogPath = APPROOT . 'log/error.log'; + $iLogIndexBefore = strrpos(file_get_contents($sLogPath), 'Broken caselog | ORCMCASELOG'); + $oLog = new ormCaseLog($sLog, $aInitialIndex); + $iLogIndexAfter = strrpos(file_get_contents($sLogPath), 'Broken caselog | ORCMCASELOG'); + + if ($bExtensionConfigured){ + $this->assertNotEquals($iLogIndexBefore, $iLogIndexAfter, 'Log line found and it must be in aother position in the log file'); + } else { + $this->assertEquals($iLogIndexBefore, $iLogIndexAfter, 'No log line found OR it is found at same position (logged before)'); + } + } +} diff --git a/tests/php-unit-tests/unitary-tests/core/ormCaseLogTest.php b/tests/php-unit-tests/unitary-tests/core/ormCaseLogTest.php index 65d424945..94d14a03d 100644 --- a/tests/php-unit-tests/unitary-tests/core/ormCaseLogTest.php +++ b/tests/php-unit-tests/unitary-tests/core/ormCaseLogTest.php @@ -237,21 +237,6 @@ class ormCaseLogTest extends ItopDataTestCase $aInitialIndex = ['a' => 'b']; $aRebuiltIndex = ['c' => 'd']; - /*$aOrmCaseLogExtensionForTest = $this->createMock(\iOrmCaseLogExtension::class); - $aOrmCaseLogExtensionForTest->expects($this->exactly(1)) - ->method('Rebuild') - ->with( - $this->callback( - function ($sLogParam, &$aIndexParam) use ($aInitialIndex, $sLog, $aRebuiltIndex, $sRebuiltLog, $bTouched) { - $sLogParam = $sRebuiltLog; - $aIndexParam = $aRebuiltIndex; - return ($sLog === $sLogParam) - && ($aInitialIndex === $sLogParam); - } - ) - ) - ->willReturn($bTouched);*/ - $aOrmCaseLogExtensionForTest = new OrmCaseLogExtensionForTest(); $aOrmCaseLogExtensionForTest->Init($bTouched, $sRebuiltLog, $aRebuiltIndex); $aOrmCaseLogExtension=[$aOrmCaseLogExtensionForTest];