Skip to content
Code-Schnipsel Gruppen Projekte
Bestätigt Commit 8134d42d erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

fix: missing brick uid -> workaround; refactor: code style and types

Übergeordneter ef7d5a10
No related branches found
No related tags found
Keine zugehörigen Merge Requests gefunden
......@@ -6,18 +6,13 @@
namespace QUI\Bricks;
use Exception;
use QUI;
use QUI\Projects\Site;
use QUI\Projects\Site\Edit;
use Smarty;
use SmartyException;
use function array_flip;
use function array_map;
use function explode;
use function is_array;
use function is_string;
use function json_decode;
use function json_encode;
use function preg_replace_callback;
......@@ -32,7 +27,7 @@
*/
class Events
{
protected static array $saved = [];
protected static $saved = [];
/**
* Event : on site save
......@@ -52,7 +47,7 @@ public static function onSiteSave($Site)
$areas = $Site->getAttribute('quiqqer.bricks.areas');
$areas = json_decode($areas, true);
if (!$areas || empty($areas)) {
if (empty($areas)) {
return;
}
......@@ -121,11 +116,11 @@ public static function onSiteSave($Site)
$customFields = [];
// Custom data cache
if (isset($brick['customfields']) && is_string($brick['customfields'])) {
if (isset($brick['customfields']) && \is_string($brick['customfields'])) {
$customFields = json_decode($brick['customfields'], true);
}
if (isset($brick['customfields']) && is_array($brick['customfields'])) {
if (isset($brick['customfields']) && \is_array($brick['customfields'])) {
$customFields = $brick['customfields'];
}
......@@ -224,10 +219,10 @@ public static function onDeleteProject(string $project)
* Event : on smarty init
* add new brickarea function
*
* @param Smarty $Smarty
* @throws SmartyException
* @param \Smarty $Smarty
* @throws \SmartyException
*/
public static function onSmartyInit(Smarty $Smarty)
public static function onSmartyInit($Smarty)
{
// {brickarea}
if (!isset($Smarty->registered_plugins['function'])
......@@ -241,7 +236,7 @@ public static function onSmartyInit(Smarty $Smarty)
* Smarty brickarea function {brickarea}
*
* @param array $params - function parameter
* @param Smarty $smarty
* @param \Smarty $smarty
* @return string|array
*/
public static function brickarea($params, $smarty)
......@@ -351,7 +346,7 @@ public static function outputParsing($match): string
$Brick = Manager::init()->getBrickById($brickId);
return QUI\Output::getInstance()->parse($Brick->create());
} catch (Exception $Exception) {
} catch (\Exception $Exception) {
}
return $match[0];
......
......@@ -8,7 +8,6 @@
use DOMElement;
use DOMXPath;
use Exception;
use QUI;
use QUI\Projects\Project;
use QUI\Projects\Site;
......@@ -23,7 +22,6 @@
use function array_values;
use function class_exists;
use function count;
use function defined;
use function explode;
use function implode;
use function in_array;
......@@ -109,7 +107,7 @@ public function __construct(bool $init = false)
}
/**
* Returns the brick's table name
* Returns the bricks table name
*
* @return String
*/
......@@ -278,8 +276,6 @@ public function deleteBrick(int $brickId)
// check if brick exist
$Brick = $this->getBrickById($brickId);
QUI::getEvents()->fireEvent('quiqqerBricksBrickDeleteBefore', [$Brick]);
QUI::getDataBase()->delete($this->getTable(), [
'id' => $brickId
]);
......@@ -288,6 +284,7 @@ public function deleteBrick(int $brickId)
unset($this->bricks[$brickId]);
}
$uniqueBrickIds = QUI::getDataBase()->fetch([
'select' => 'siteId, project, lang',
'from' => QUI\Bricks\Manager::getUIDTable(),
......@@ -318,8 +315,6 @@ public function deleteBrick(int $brickId)
'project' => $Brick->getAttribute('project'),
'lang' => $Brick->getAttribute('lang')
]);
QUI::getEvents()->fireEvent('quiqqerBricksBrickDeleteAfter', [$brickId]);
}
/**
......@@ -454,8 +449,7 @@ public function getAvailableBricks(): array
'quiqqer/bricks',
'brick.content.description'
],
'control' => 'content',
'deprecated' => 0
'control' => 'content'
];
foreach ($xmlFiles as $bricksXML) {
......@@ -475,7 +469,7 @@ public function getAvailableBricks(): array
try {
QUI\Cache\Manager::set($cache, $list);
} catch (Exception $Exception) {
} catch (\Exception $Exception) {
QUI\System\Log::writeException($Exception);
}
......@@ -520,12 +514,12 @@ public function getBrickById(int $id): Brick
* Get a Brick by its unique ID
*
* @param string $uid - unique id
* @param QUI\Interfaces\Projects\Site|null $Site - unique id
* @param Site|null $Site - unique id
*
* @return Brick
* @throws QUI\Exception
*/
public function getBrickByUID(string $uid, ?QUI\Interfaces\Projects\Site $Site = null): Brick
public function getBrickByUID(string $uid, $Site = null): Brick
{
if (isset($this->brickUIDs[$uid])) {
return $this->brickUIDs[$uid];
......@@ -672,7 +666,7 @@ public function getAvailableBrickSettingsByBrickType($brickType): array
try {
QUI\Cache\Manager::set($cache, $settings);
} catch (Exception $Exception) {
} catch (\Exception $Exception) {
QUI\System\Log::writeException($Exception);
}
......@@ -682,22 +676,18 @@ public function getAvailableBrickSettingsByBrickType($brickType): array
/**
* Parse a xml setting element to a brick array
*
* @param DOMElement $Setting
* @param \DOMElement $Setting
* @return array
*/
protected function parseSettingToBrickArray(DOMElement $Setting): array
{
/* @var $Option DOMElement */
/* @var $Option \DOMElement */
$options = false;
if ($Setting->getAttribute('type') == 'select') {
$optionElements = $Setting->getElementsByTagName('option');
foreach ($optionElements as $Option) {
if (!$options) {
$options = [];
}
$options[] = [
'value' => $Option->getAttribute('value'),
'text' => QUI\Utils\DOM::getTextFromNode($Option, false)
......@@ -776,14 +766,10 @@ public function getBricksByArea(
$result = [];
try {
QUI::getEvents()->fireEvent(
'onQuiqqerBricksGetBricksByAreaBegin',
[$brickArea, $Site, &$result]
);
} catch (QUI\Exception $e) {
QUI\System\Log::addError($e->getMessage());
}
QUI::getEvents()->fireEvent(
'onQuiqqerBricksGetBricksByAreaBegin',
[$brickArea, $Site, &$result]
);
foreach ($bricks as $brickData) {
$brickId = (int)$brickData['brickId'];
......@@ -794,7 +780,10 @@ public function getBricksByArea(
$result[] = $Brick->check();
continue;
}
} catch (QUI\Exception $Exception) {
}
try {
if (!$brickId) {
continue;
}
......@@ -818,14 +807,10 @@ public function getBricksByArea(
}
}
try {
QUI::getEvents()->fireEvent(
'onQuiqqerBricksGetBricksByAreaEnd',
[$brickArea, $Site, &$result]
);
} catch (QUI\Exception $e) {
QUI\System\Log::addError($e->getMessage());
}
QUI::getEvents()->fireEvent(
'onQuiqqerBricksGetBricksByAreaEnd',
[$brickArea, $Site, &$result]
);
return $result;
}
......@@ -935,7 +920,6 @@ public function saveBrick($brickId, array $brickData)
$brickData['areas'] = $brickData['attributes']['areas'];
}
if (isset($brickData['areas'])) {
$parts = explode(',', $brickData['areas']);
......@@ -1234,7 +1218,7 @@ protected function getInheritedBricks(
continue;
}
if (empty($bricks) || !is_array($bricks)) {
if (empty($bricks)) {
continue;
}
......
0% oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren