Skip to content

Commit

Permalink
Merge pull request #72 from openjournalteam/fix_uncaught_type_error
Browse files Browse the repository at this point in the history
check when null file on log error
  • Loading branch information
rahmanramsi authored Mar 29, 2024
2 parents fa4effc + 7dfe904 commit 6ccba22
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### 2.0.8.1 : 08 Februari 2024
- Fix error handler when there's no file on error log

### 2.0.8.0 : 08 Februari 2024
- Some enhancement in OJT Plugin

### 2.0.7.1 : 28 Nov 2023
- Fix error when installing plugin because ojs root folder is restricted to write

Expand Down
29 changes: 23 additions & 6 deletions OjtPlugin.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,13 @@ function fatalHandler()
$error = error_get_last();
// Fatal error, E_ERROR === 1
if (array_key_exists('type', $error) && !in_array($error['type'], [E_COMPILE_ERROR, E_ERROR])) return;
if (!str_contains($error['file'], 'ojtPlugin')) {

// Sometime there's no file in error so we need to check it first
if (!array_key_exists('file', $error)) return;



if (!$this->str_contains($error['file'], 'ojtPlugin')) {
return;
}

Expand Down Expand Up @@ -176,11 +182,13 @@ public function setLogger()
static::deleteLogFile();
};

$logger->log(
LogLevel::ERROR,
sprintf('Uncaught Exception %s: "%s" at %s line %s', Utils::getClass($e), $e->getMessage(), $e->getFile(), $e->getLine()),
['exception' => $e]
);
if ($this->str_contains($e->getFile(), 'ojtPlugin')) {
$logger->log(
LogLevel::ERROR,
sprintf('Uncaught Exception %s: "%s" at %s line %s', Utils::getClass($e), $e->getMessage(), $e->getFile(), $e->getLine()),
['exception' => $e]
);
}

throw $e;
});
Expand Down Expand Up @@ -726,4 +734,13 @@ public function isDiagnosticEnabled()
{
return $this->getSetting(CONTEXT_SITE, 'enable_diagnostic') ?? true;
}

function str_contains($haystack, $needle)
{
if(!$haystack){
return false;
}

return $needle !== '' && mb_strpos($haystack, $needle) !== false;
}
}
9 changes: 1 addition & 8 deletions helpers/OJTHelper.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,4 @@ function vd($value)
var_dump($value);
echo '</pre>';
}
}

if (!function_exists('str_contains')) {
function str_contains($haystack, $needle)
{
return $needle !== '' && mb_strpos($haystack, $needle) !== false;
}
}
}
4 changes: 2 additions & 2 deletions version.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<version>
<application>ojtPlugin</application>
<type>plugins.generic</type>
<release>2.0.8.0</release>
<date>2024-02-08</date>
<release>2.0.8.1</release>
<date>2024-03-29</date>
<lazy-load>0</lazy-load>
<class>OjtPlugin</class>
</version>

0 comments on commit 6ccba22

Please sign in to comment.