Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
akrys committed Apr 27, 2024
2 parents 990ae5d + 2d3fae7 commit fd4e02f
Show file tree
Hide file tree
Showing 33 changed files with 357 additions and 245 deletions.
3 changes: 2 additions & 1 deletion FriendsOfRedaxo/addon/UsageCheck/Addon.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use FriendsOfRedaxo\addon\UsageCheck\Exception\CloneException;
use rex_addon;
use rex_addon_interface;

/**
* Description of Addon
Expand All @@ -20,7 +21,7 @@ final class Addon
{
/**
* Addon
* @var \rex_addon
* @var rex_addon_interface
*/
private $addon;

Expand Down
28 changes: 2 additions & 26 deletions FriendsOfRedaxo/addon/UsageCheck/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,11 @@ class Config
/**
* (Absolutes) Basis Verzeichnis holen
* @return string
*/
public static function getBaseDir()
{
return realpath(__DIR__.'/../../../');
}

/**
* Test, ob das Vendor-Verzeichnis gelöscht wurde.
*
* Performance-Probleme durch den rex_autoloader verhindern.
* Dieser versucht alle Dateien zu analysieren.
*
* @throws Exception
* @codeCoverageIgnore
*/
public static function checkVendorDir()
public static function getBaseDir()
{
if (!isset($_SERVER['argv'])) {
$vendorDir = self::getBaseDir().'/vendor';
if (file_exists($vendorDir) && is_dir($vendorDir)) {
throw new Exception('Please delete '.realpath($vendorDir));
}

// $nodeDir = self::getBaseDir().'/node_modules';
// if(file_exists($nodeDir) && is_dir($nodeDir)){
// throw new \Exception('Please delete '.realpath($nodeDir));
// }
}
return true;
return (string) realpath(__DIR__.'/../../../');
}

/**
Expand Down
5 changes: 3 additions & 2 deletions FriendsOfRedaxo/addon/UsageCheck/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* einem einfachen foreach durlaufen werden können.
*
* @author akrys
* @implements Iterator<string>
*/
class Error implements Iterator
{
Expand Down Expand Up @@ -79,7 +80,7 @@ public function next(): void
public function current(): string
{
if (!$this->valid()) {
return false;
return '';
}
return $this->errors[$this->index];
}
Expand Down Expand Up @@ -162,7 +163,7 @@ final public function __clone()

/**
* Fehlerausgabe
* @param array $messages
* @param array<string, mixed> $messages
*/
public static function getMessageOutputFragment(array $messages): rex_fragment
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Scripting/PHPClass.php to edit this template
*/
namespace FriendsOfRedaxo\addon\UsageCheck\Exception;

use Exception;

/**
* Datei für ...
*
* @version 1.0 / 2024-03-24
* @author akrys
*/

/**
* Description of InvalidParameterException
*
* @author akrys
*/
class InvalidParameterException extends Exception
{
//put your code here
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Scripting/PHPClass.php to edit this template
*/
namespace FriendsOfRedaxo\addon\UsageCheck\Exception;

/**
* Datei für ...
*
* @version 1.0 / 2024-03-24
* @author akrys
*/

/**
* Description of MediumNotFoundException
*
* @author akrys
*/
class MediaNotFoundException extends \Exception
{

public function __construct(
private string $filename,
string $message = "",
int $code = 0,
?\Throwable $previous = null
) {
parent::__construct($message, $code, $previous);
}

public function getFilename(): string
{
return $this->filename;
}
}
14 changes: 10 additions & 4 deletions FriendsOfRedaxo/addon/UsageCheck/Lib/BaseModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,28 @@ abstract class BaseModule extends RexBase

/**
* Tabellenfelder
* @var array
* @var array<string, mixed>
*/
protected array $tableFields = [];

/**
* Anzeigemodus umstellen
* @param boolean $bln
*/
public function showAll(bool $bln)
public function showAll(bool $bln): void
{
$this->showAll = $bln;
}

/**
* Rechte prüfen
* @return bool
*/
abstract public function hasPerm(): bool;

/**
* Daten holen
* @return array
* @return array<int|string, mixed>
*/
abstract public function get(): array;

Expand All @@ -52,7 +58,7 @@ abstract protected function getSQL(int $datail_id = null): string;
/**
* Details holen
* @param int $item_id
* @return array
* @return array<string, mixed>
*/
abstract public function getDetails(int $item_id): array;
}
16 changes: 8 additions & 8 deletions FriendsOfRedaxo/addon/UsageCheck/Lib/FileSize.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ class FileSize
{
/**
* Dateigröße, die analysiert werden soll.
* @var int
* @var int|float
*/
private int $size;
private int|float $size;

/**
* Konstruktor
*
* @param int $size
* @param int|float $size
*/
public function __construct(int $size)
public function __construct(int|float $size)
{
$this->size = $size;
}
Expand Down Expand Up @@ -79,10 +79,10 @@ public function getSizeOut(): string
*
* Dabei zählen, wie oft man sie verkleinern konnte. Daraus ergibt sich die Einheit.
*
* @param int $size
* @return array Indezes: index, size
* @param int|float $size
* @return array<string, mixed> Indezes: index, size
*/
private function getSizeReadable(int $size): array
private function getSizeReadable(int|float $size): array
{
$return = [
'index' => 0,
Expand All @@ -91,7 +91,7 @@ private function getSizeReadable(int $size): array

$return['index'] = 0;

while ($return['size'] > 1024 && $return['index'] <= 6) {
while ($return['size'] >= 1024 && $return['index'] <= 6) {
$return['index']++;
$return['size'] /= 1024;
}
Expand Down
16 changes: 9 additions & 7 deletions FriendsOfRedaxo/addon/UsageCheck/Lib/PictureYFrom.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ class PictureYFrom extends RexBase
* SQL Partsfür YForm generieren.
*
* @param int $detail_id
* @return array
* @return array<string, mixed>
* @SuppressWarnings(PHPMD.ElseExpression)
* -> zu tief verschachtelt.... vllt. Funktionsauslagerung?
*/
public function getYFormTableSQLParts(int $detail_id = null): array
{
Expand Down Expand Up @@ -65,7 +67,7 @@ public function getYFormTableSQLParts(int $detail_id = null): array
$return['additionalJoins'] .= ' OR ';
}

$return['additionalJoins'] .= $this->getJoinCondition($field, $tableName);
$return['additionalJoins'] .= $this->getJoinCondition($field, (string) $tableName);
}

$return['tableFields'][$tableName] = $fields;
Expand All @@ -78,8 +80,7 @@ public function getYFormTableSQLParts(int $detail_id = null): array
/**
* YFormTables holen
*
* @return array
* @param array &$return
* @return array<int, array<string, bool|float|int|string|null>>
*/
public function getYFormSQL(): array
{
Expand Down Expand Up @@ -139,7 +140,7 @@ public function getYFormSQL(): array
* zu können.
*
* @param string $yformFieldTable
* @param array $dbs
* @param array<string, mixed> $dbs
* @returns boolean
* @SuppressWarnings(PHPMD.StaticAccess)
*/
Expand All @@ -152,9 +153,10 @@ private function hasMultiple(string $yformFieldTable, ?array $dbs = null): bool
}

$where = [];
$params = [];
foreach ($dbs as $db) {
if (isset($db['name']) && $db['name'] != '') {
$where[] .= "(TABLE_NAME=? and TABLE_SCHEMA=? and COLUMN_NAME='multiple')";
$where[] = "(TABLE_NAME=? and TABLE_SCHEMA=? and COLUMN_NAME='multiple')";
$params[] = $yformFieldTable;
$params[] = $db['name'];
}
Expand All @@ -180,7 +182,7 @@ private function hasMultiple(string $yformFieldTable, ?array $dbs = null): bool
* Das dürfte an der Anpassung zu YForm 2 liegen, da dort in be_media nun mehrere Dateien angegeben werden dürfen.
* Die Prüfung auf $field['multiple'] ist dann eine ebene zu tief.
*
* @param array $field
* @param array<string, mixed> $field
* @param string $tableName
* @return string
*/
Expand Down
9 changes: 7 additions & 2 deletions FriendsOfRedaxo/addon/UsageCheck/Lib/RexBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace FriendsOfRedaxo\addon\UsageCheck\Lib;

use Exception;
use FriendsOfRedaxo\addon\UsageCheck\Exception\InvalidParameterException;
use rex;
use rex_sql;

Expand All @@ -21,9 +22,9 @@ class RexBase
{
/**
* rexSQL instanz
* @var rex_sql
* @var ?rex_sql
*/
private rex_sql $rexSql;
private ?rex_sql $rexSql;

/**
* rex Instanz
Expand Down Expand Up @@ -69,9 +70,13 @@ public function setRexSql(rex_sql $sql): self
* lt. phpmd sollte man nicht statisch drauf zugreifen
* @param string $table
* @return string
* @throws InvalidParameterException
*/
protected function getTable(string $table): string
{
if ($table === '') {
throw new InvalidParameterException('Paramer $table should not be empty');
}
if (!$this->rex) {
$this->rex = new rex;
}
Expand Down
14 changes: 10 additions & 4 deletions FriendsOfRedaxo/addon/UsageCheck/Medium.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@ class Medium
/**
* Holt ein Medium-Objekt mit Prüfung der Rechte
*
* @param array $item Idezes: category_id, filename
* @param array<string, mixed> $item Idezes: category_id, filename
* @return rex_media
* @throws FunctionNotCallableException
* @SuppressWarnings(PHPMD.StaticAccess)
*/
public static function get(array $item): rex_media
{
$user = rex::getUser();
$complexPerm = $user->getComplexPerm('media');
if (!$user->isAdmin() &&
/**
* @var \rex_media_perm $complexPerm
*/
$complexPerm = $user?->getComplexPerm('media');
if (!$user?->isAdmin() &&
!(is_object($complexPerm) &&
$complexPerm->hasCategoryPerm($item['category_id']))) {
//keine Rechte am Medium
Expand All @@ -43,14 +46,17 @@ public static function get(array $item): rex_media
//Das Medium wird später gebraucht.
/* @var $medium rex_media */
$medium = rex_media::get($item['filename']);
if (!$medium) {
throw new Exception\MediaNotFoundException('Medium '.$item['filename'].' not found');
}
return $medium;
}

/**
* Überprüfen, ob eine Datei existiert.
*
* @global type $REX
* @param array $item
* @param array<string, mixed> $item
* @return boolean
* @SuppressWarnings(PHPMD.StaticAccess)
*/
Expand Down
Loading

0 comments on commit fd4e02f

Please sign in to comment.