Skip to content
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
11 changes: 5 additions & 6 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -624,12 +624,11 @@ function plugin_example_uninstall()
ProfileRight::deleteProfileRights([Example::$rightname]);

$notif = new Notification();
$options = ['itemtype' => 'Ticket',
'event' => 'plugin_example',
'FIELDS' => 'id'];
foreach ($DB->request('glpi_notifications', $options) as $data) {
$notif->delete($data);
}
$notif->deleteByCriteria([
'itemtype' => 'Ticket',
'event' => 'plugin_example',
'FIELDS' => 'id',
]);
// Old version tables
if ($DB->tableExists('glpi_dropdown_plugin_example')) {
$query = 'DROP TABLE `glpi_dropdown_plugin_example`';
Expand Down
15 changes: 10 additions & 5 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
includes:
- ../../vendor/glpi-project/phpstan-glpi/extension.neon
- ../../vendor/phpstan/phpstan-deprecation-rules/rules.neon
- ../../vendor/thecodingmachine/phpstan-safe-rule/phpstan-safe-rule.neon

parameters:
parallel:
maximumNumberOfProcesses: 2
level: 5
paths:
- front
Expand All @@ -10,10 +13,12 @@ parameters:
- setup.php
- stat.php
scanDirectories:
- ../../inc
- ../../src
- ../../front
bootstrapFiles:
- ../../stubs/glpi_constants.php
- ../../vendor/autoload.php

- setup.php
treatPhpDocTypesAsCertain: false
ignoreErrors:
- message: "#.*always true#"
- message: "#Unreachable statement#"
2 changes: 2 additions & 0 deletions report.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
* -------------------------------------------------------------------------
*/

use function Safe\define;

// ----------------------------------------------------------------------
// Original Author of file:
// Purpose of file:
Expand Down
2 changes: 2 additions & 0 deletions setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
use GlpiPlugin\Example\RuleTestCollection;
use GlpiPlugin\Example\Showtabitem;

use function Safe\define;

define('PLUGIN_EXAMPLE_VERSION', '0.1.0');

// Minimal GLPI version, inclusive
Expand Down
25 changes: 15 additions & 10 deletions src/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,17 @@

namespace GlpiPlugin\Example;

use Glpi\Exception\Http\NotFoundHttpException;
use Glpi\Exception\Http\HttpException;
use Document as GlpiDocument;

use function Safe\filemtime;
use function Safe\filesize;
use function Safe\fopen;
use function Safe\fread;
use function Safe\preg_match;
use function Safe\set_time_limit;

class Document extends GlpiDocument
{
/**
Expand Down Expand Up @@ -142,8 +151,7 @@ protected function sendFile()

// Ensure the file exists
if (!file_exists($streamSource) || !is_file($streamSource)) {
header('HTTP/1.0 404 Not Found');
exit(0);
throw new NotFoundHttpException();
}

// Download range defaults to the full file
Expand All @@ -157,8 +165,7 @@ protected function sendFile()
// Open the file
$fileHandle = @fopen($streamSource, 'rb');
if (!$fileHandle) {
header('HTTP/1.0 500 Internal Server Error');
exit(0);
throw new HttpException(500, 'Internal Server Error');
}

// set range if specified by the client
Expand All @@ -174,8 +181,7 @@ protected function sendFile()
// seek to the begining of the range
$currentPosition = $begin;
if (fseek($fileHandle, $begin, SEEK_SET) < 0) {
header('HTTP/1.0 500 Internal Server Error');
exit(0);
throw new HttpException(500, 'Internal Server Error');
}

// send headers to ensure the client is able to detect a corrupted download
Expand Down Expand Up @@ -206,9 +212,8 @@ protected function sendFile()
// allow a few seconds to send a few KB.
set_time_limit(10);
$content = fread($fileHandle, min(1024 * 16, $end - $currentPosition + 1));
if ($content === false) {
header('HTTP/1.0 500 Internal Server Error', true); // Replace previously sent headers
exit(0);
if (empty($content)) {
throw new HttpException(500, 'Internal Server Error');
} else {
print $content;
}
Expand All @@ -217,6 +222,6 @@ protected function sendFile()
}

// End now to prevent any unwanted bytes
exit(0);
return;
}
}
2 changes: 2 additions & 0 deletions src/Example.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
use Session;
use Supplier;

use function Safe\strtotime;

// Class of the defined type
class Example extends CommonDBTM
{
Expand Down
2 changes: 2 additions & 0 deletions stat.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
* -------------------------------------------------------------------------
*/

use function Safe\define;

// ----------------------------------------------------------------------
// Original Author of file:
// Purpose of file:
Expand Down