Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
akrys committed Feb 20, 2020
2 parents 20b9c7d + 7ac5392 commit d375cc4
Show file tree
Hide file tree
Showing 30 changed files with 355 additions and 223 deletions.
80 changes: 80 additions & 0 deletions FriendsOfRedaxo/addon/UsageCheck/Addon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

/**
* Datei für ...
*
* @version 1.0 / 2020-02-18
* @author akrys
*/
namespace FriendsOfRedaxo\addon\UsageCheck;

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

/**
* Description of Addon
*
* @author akrys
*/
final class Addon
{
/**
* Addon
* @var \rex_addon
*/
private $addon;

/**
* Version holen, besser direkt über die yml-Datei
* @return string
*/
public function getVersion()
{
return $this->addon->getVersion();
}

/**
* Name holen, besser direkt über die yml-Datei
* @return string
*/
public function getName()
{
$page = $this->addon->getProperty('page');
return $page['title'];
}
// <editor-fold defaultstate="collapsed" desc="Singleton">
/**
* Instance
* @var Error
*/
private static $instance = null;

/**
* create Singleton Instance
* @return Error
*/
public static function getInstance()
{
if (self::$instance == null) {
self::$instance = new self();
}
return self::$instance;
}

/**
* Konstuktor
*/
final private function __construct()
{
$this->addon = rex_addon::get(Config::NAME);
}

/**
* forbid cloning
*/
final public function __clone()
{
throw new CloneException();
}
// </editor-fold>
}
11 changes: 6 additions & 5 deletions FriendsOfRedaxo/addon/UsageCheck/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@ class Config

/**
* Ausgabename des Addons
* @deprecated
* @var string
*/
const NAME_OUT = 'Usage Check';
const NAME_OUT = 'migrate to \FriendsOfRedaxo\addon\UsageCheck\Addon::getInstance()->getName()';

/**
* Version des Addons
*
* @deprecated
* @var string
*/
const VERSION = '2.2';
const VERSION = 'migrate to \FriendsOfRedaxo\addon\UsageCheck\Addon::class::getInstance()->getVersion()';

/**
* release state
Expand Down Expand Up @@ -64,15 +65,15 @@ public static function getBaseDir()
* Performance-Probleme durch den rex_autoloader verhindern.
* Dieser versucht alle Dateien zu analysieren.
*
* @throws \Exception
* @throws Exception
* @codeCoverageIgnore
*/
public static function checkVendorDir()
{
if (!isset($_SERVER['argv'])) {
$vendorDir = self::getBaseDir().'/vendor';
if (file_exists($vendorDir) && is_dir($vendorDir)) {
throw new \Exception('Please delete '.realpath($vendorDir));
throw new Exception('Please delete '.realpath($vendorDir));
}

// $nodeDir = self::getBaseDir().'/node_modules';
Expand Down
28 changes: 16 additions & 12 deletions FriendsOfRedaxo/addon/UsageCheck/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
*/
namespace FriendsOfRedaxo\addon\UsageCheck;

use FriendsOfRedaxo\addon\UsageCheck\Exception\CloneException;
use Iterator;
use rex_fragment;

/**
* Container für Fehlermeldungen
*
Expand All @@ -19,7 +23,7 @@
* @author akrys
*/
class Error
implements \Iterator
implements Iterator
{
/**
* Error Messages
Expand Down Expand Up @@ -47,16 +51,16 @@ public function add($text)
*
* @return int
*/
public function count(){
public function count()
{
return count($this->errors);
}

// <editor-fold defaultstate="collapsed" desc="Iterator Implementation">

/**
* Move forward to next element
*
* @see \Iterator::next()
* @see Iterator::next()
* @link https://secure.php.net/manual/en/iterator.next.php
*
* @return int
Expand All @@ -70,7 +74,7 @@ public function next()
/**
* Return the current element
*
* @see \Iterator::current()
* @see Iterator::current()
* @link https://secure.php.net/manual/en/iterator.current.php
*
* @return string
Expand All @@ -86,7 +90,7 @@ public function current()
/**
* Rewind the Iterator to the first element
*
* @see \Iterator::rewind()
* @see Iterator::rewind()
* @link https://secure.php.net/manual/en/iterator.rewind.php
*/
public function rewind()
Expand All @@ -97,7 +101,7 @@ public function rewind()
/**
* Return the key of the current element
*
* @see \Iterator::key()
* @see Iterator::key()
* @link https://secure.php.net/manual/en/iterator.key.php
*
* @return int
Expand All @@ -110,7 +114,7 @@ public function key()
/**
* Checks if current position is valid
*
* @see \Iterator::valid()
* @see Iterator::valid()
* @link https://secure.php.net/manual/en/iterator.valid.php
*
* @return boolean
Expand Down Expand Up @@ -155,12 +159,12 @@ final private function __construct()
*/
final public function __clone()
{
throw new Exception\CloneException();
throw new CloneException();
}
// </editor-fold>

/**
*
* Fehlerausgabe
* @param type $messages
*/
public static function getMessageOutputFragment($messages)
Expand All @@ -169,14 +173,14 @@ public static function getMessageOutputFragment($messages)
$text = '';
foreach ($messages as $error) {
if (trim($error) !== '') {
$fragment = new \rex_fragment([
$fragment = new rex_fragment([
'text' => $error,
]);

$text .= $fragment->parse('fragments/msg/tagged_msg.php');
}
}
$fragment = new \rex_fragment([
$fragment = new rex_fragment([
'text' => $text,
]);

Expand Down
6 changes: 0 additions & 6 deletions FriendsOfRedaxo/addon/UsageCheck/Lib/BaseModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ abstract class BaseModule
*/
protected $showAll = false;

/**
*
* @var type
*/
protected $detailId = null;

/**
* Tabellenfelder
* @var array
Expand Down
11 changes: 8 additions & 3 deletions FriendsOfRedaxo/addon/UsageCheck/Lib/PictureYFrom.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
*/
namespace FriendsOfRedaxo\addon\UsageCheck\Lib;

use FriendsOfRedaxo\addon\UsageCheck\Lib\RexBase;
use rex;
use rex_addon;
use rex_plugin;

/**
* Description of PictureYFrom
*
Expand Down Expand Up @@ -83,11 +88,11 @@ public function getYFormSQL()

$rexSQL = $this->getRexSql();

if (!\rex_addon::get('yform')->isAvailable()) {
if (!rex_addon::get('yform')->isAvailable()) {
return $tabels;
}

if (!\rex_plugin::get('yform', 'manager')->isAvailable()) {
if (!rex_plugin::get('yform', 'manager')->isAvailable()) {
return $tabels;
}

Expand Down Expand Up @@ -145,7 +150,7 @@ private function hasMultiple($yformFieldTable, $dbs = null)
$rexSQL = $this->getRexSql();

if (!isset($dbs)) { // Normalfall, wenn wir nicht gerade Unit-Tests laufen lassen
$dbs = \rex::getProperty('db');
$dbs = rex::getProperty('db');
}

$where = array();
Expand Down
18 changes: 11 additions & 7 deletions FriendsOfRedaxo/addon/UsageCheck/Lib/RexBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
*/
namespace FriendsOfRedaxo\addon\UsageCheck\Lib;

use Exception;
use rex;
use rex_sql;

/**
* Description of RexBase
*
Expand All @@ -17,13 +21,13 @@ class RexBase
{
/**
* rexSQL instanz
* @var \rex_sql
* @var rex_sql
*/
private $rexSql;

/**
* rex Instanz
* @var \rex
* @var rex
*/
private $rex;

Expand All @@ -38,23 +42,23 @@ public function __construct()
/**
* sql-Instanz verwalten
*
* @return \rex_sql
* @return rex_sql
*/
public function getRexSql()
{
if (!$this->rexSql) {
throw new \Exception('no sql given');
throw new Exception('no sql given');
}

return $this->rexSql;
}

/**
* sql-Instanz verwalten
* @param \rex_sql $sql
* @param rex_sql $sql
* @return $this
*/
public function setRexSql(\rex_sql $sql)
public function setRexSql(rex_sql $sql)
{
$this->rexSql = $sql;
return $this;
Expand All @@ -69,7 +73,7 @@ public function setRexSql(\rex_sql $sql)
protected function getTable($table)
{
if (!$this->rex) {
$this->rex = new \rex;
$this->rex = new rex;
}
return $this->rex->getTable($table);
}
Expand Down
19 changes: 12 additions & 7 deletions FriendsOfRedaxo/addon/UsageCheck/Medium.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
*/
namespace FriendsOfRedaxo\addon\UsageCheck;

use FriendsOfRedaxo\addon\UsageCheck\Exception\FunctionNotCallableException;
use rex;
use rex_media;
use rex_path;

/**
* Description of Medium
*
Expand All @@ -20,24 +25,24 @@ class Medium
* Holt ein Medium-Objekt mit Prüfung der Rechte
*
* @param array $item Idezes: category_id, filename
* @return \rex_media
* @throws \FriendsOfRedaxo\addon\UsageCheck\Exception\FunctionNotCallableException
* @return rex_media
* @throws FunctionNotCallableException
* @SuppressWarnings(PHPMD.StaticAccess)
*/
public static function get($item)
{
$user = \rex::getUser();
$user = rex::getUser();
$complexPerm = $user->getComplexPerm('media');
if (!$user->isAdmin() &&
!(is_object($complexPerm) &&
$complexPerm->hasCategoryPerm($item['category_id']))) {
//keine Rechte am Medium
throw new \FriendsOfRedaxo\addon\UsageCheck\Exception\FunctionNotCallableException();
throw new FunctionNotCallableException();
}

//Das Medium wird später gebraucht.
/* @var $medium \rex_media */
$medium = \rex_media::get($item['filename']);
/* @var $medium rex_media */
$medium = rex_media::get($item['filename']);
return $medium;
}

Expand All @@ -51,6 +56,6 @@ public static function get($item)
*/
public static function exists($item)
{
return file_exists(\rex_path::media().DIRECTORY_SEPARATOR.$item['filename']);
return file_exists(rex_path::media().DIRECTORY_SEPARATOR.$item['filename']);
}
}
Loading

0 comments on commit d375cc4

Please sign in to comment.