Skip to content

Commit

Permalink
Merge pull request #82 from FriendsOfREDAXO/category-get-fix
Browse files Browse the repository at this point in the history
Category-Id Field-Method-Fix
  • Loading branch information
alxndr-w authored Aug 16, 2024
2 parents f7a5c81 + c5e08aa commit d6db739
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 41 deletions.
14 changes: 8 additions & 6 deletions boot.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use rex_be_controller;
use rex_config;
use rex_cronjob_manager;
use rex_cronjob_neues_publish;
use rex_cronjob_neues_sync;
use rex_csrf_token;
use rex_extension;
use rex_extension_point;
Expand All @@ -17,8 +19,8 @@
use rex_yform_manager_table;

if (rex_addon::get('cronjob')->isAvailable() && !rex::isSafeMode()) {
rex_cronjob_manager::registerType(\rex_cronjob_neues_publish::class);
rex_cronjob_manager::registerType(\rex_cronjob_neues_sync::class);
rex_cronjob_manager::registerType(rex_cronjob_neues_publish::class);
rex_cronjob_manager::registerType(rex_cronjob_neues_sync::class);
}

if (rex_addon::get('yform')->isAvailable() && !rex::isSafeMode()) {
Expand Down Expand Up @@ -94,7 +96,7 @@ static function ($a) {
$category_ids = array_filter(array_map('intval', explode(',', $a['value'])));

foreach ($category_ids as $category_id) {
/** @var $neues_category neues_category */
/** @var neues_category $neues_category */
$neues_category = Category::get($category_id);
if ($neues_category) {
$return[] = '<a href="' . rex_url::backendPage('neues/category', $params) . '">' . $neues_category->getName() . '</a>';
Expand All @@ -106,13 +108,13 @@ static function ($a) {
}
});

if (rex::isBackend() && \rex_addon::get('neues') && \rex_addon::get('neues')->isAvailable() && !rex::isSafeMode()) {
if (rex::isBackend() && rex_addon::get('neues') && rex_addon::get('neues')->isAvailable() && !rex::isSafeMode()) {
$addon = rex_addon::get('neues');
$pages = $addon->getProperty('pages');

if($_REQUEST) {
if ($_REQUEST) {
$_csrf_key = rex_yform_manager_table::get('rex_neues_entry')->getCSRFKey();

$token = rex_csrf_token::factory($_csrf_key)->getUrlParams();

$params = [];
Expand Down
6 changes: 3 additions & 3 deletions install.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use rex;
use rex_addon;
use rex_article;
use rex_config;
use rex_file;
use rex_media;
Expand All @@ -23,7 +24,6 @@
$sql->setQuery('UPDATE ' . rex::getTable('neues_entry') . ' SET uuid = uuid() WHERE uuid IS NULL OR uuid = ""');

require_once __DIR__ . '/install/update_scheme.php';

}

if (!rex_media::get('neues_entry_fallback_image.png')) {
Expand Down Expand Up @@ -53,12 +53,12 @@
if (false === rex_config::get('neues', 'url_profile', false)) {
$rex_neues_category = array_filter(rex_sql::factory()->getArray("SELECT * FROM rex_url_generator_profile WHERE `table_name` = '1_xxx_rex_neues_category'"));
if (!$rex_neues_category) {
$query = \str_replace("999999", \rex_article::getSiteStartArticleId(), rex_file::get(__DIR__ . '/install/rex_url_profile_neues_category.sql'));
$query = str_replace('999999', rex_article::getSiteStartArticleId(), rex_file::get(__DIR__ . '/install/rex_url_profile_neues_category.sql'));
rex_sql::factory()->setQuery($query);
}
$rex_neues_entry = array_filter(rex_sql::factory()->getArray("SELECT * FROM rex_url_generator_profile WHERE `table_name` = '1_xxx_rex_neues_entry'"));
if (!$rex_neues_entry) {
$query = \str_replace("999999", \rex_article::getSiteStartArticleId(), rex_file::get(__DIR__ . '/install/rex_url_profile_neues_entry.sql'));
$query = str_replace('999999', rex_article::getSiteStartArticleId(), rex_file::get(__DIR__ . '/install/rex_url_profile_neues_entry.sql'));
rex_sql::factory()->setQuery($query);
}
/* URL-Profile wurden bereits einmal installiert, daher nicht nochmals installieren und Entwickler-Einstellungen respektieren */
Expand Down
2 changes: 0 additions & 2 deletions install/update_scheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,3 @@
->ensureColumn(new rex_sql_column('category_id', 'int(10) unsigned'))
->ensureIndex(new rex_sql_index('entry_id_category_id', ['entry_id', 'category_id'], rex_sql_index::UNIQUE))
->ensure();

?>
4 changes: 0 additions & 4 deletions lib/neues.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@

namespace FriendsOfRedaxo\Neues;

use rex;
use rex_fragment;
use rex_pager;
use rex_sql;
use rex_sql_column;
use rex_sql_index;
use rex_sql_table;

class Neues
{
Expand Down
2 changes: 1 addition & 1 deletion lib/neues_category.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function setName(string $name): self
*/
public function getEntries(): ?rex_yform_manager_collection
{
return $this->getRelatedCollection('entry_ids');
return $this->getRelatedCollection('date_id');
}

/**
Expand Down
21 changes: 10 additions & 11 deletions lib/neues_restful_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

namespace FriendsOfRedaxo\Neues;

use rex_yform_rest_route;
use rex_yform_rest;
use rex_yform_rest_route;

class RestfulApi {

public static function init() :void {
class RestfulApi
{
public static function init(): void
{
$rex_neues_entry_route = new rex_yform_rest_route(
[
'path' => '/neues/entry/5.0.0/',
Expand Down Expand Up @@ -92,9 +93,9 @@ public static function init() :void {
],
],
);

rex_yform_rest::addRoute($rex_neues_entry_route);

/* YForm Rest API */
$rex_neues_category_route = new rex_yform_rest_route(
[
Expand Down Expand Up @@ -136,9 +137,9 @@ public static function init() :void {
],
],
);

rex_yform_rest::addRoute($rex_neues_category_route);

/* YForm Rest API */
$rex_neues_author_route = new rex_yform_rest_route(
[
Expand Down Expand Up @@ -183,9 +184,7 @@ public static function init() :void {
],
],
);

rex_yform_rest::addRoute($rex_neues_author_route);

}

}
4 changes: 2 additions & 2 deletions lib/rex_cronjob_neues_publish.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php


use FriendsOfRedaxo\Neues\Entry;

use function count;

Expand All @@ -9,7 +9,7 @@ class rex_cronjob_neues_publish extends rex_cronjob
public function execute()
{
/* Collection von Neues-Einträgen, die noch nicht veröffentlicht sind, aber es sein sollten. (geplant) */
$neues_entry_to_publish = FriendsOfRedaxo\Neues\Entry::query()->where('status', 0)->where('publishdate', date('Y-m-d'), '<')->find();
$neues_entry_to_publish = Entry::query()->where('status', 0)->where('publishdate', date('Y-m-d'), '<')->find();
$neues_entry_to_publish->setValue('status', 1);
if (!$neues_entry_to_publish->save()) {
$this->setMessage(sprintf(rex_i18n::msg('neues_entry_publish_error'), count($neues_entry_to_publish)));
Expand Down
25 changes: 13 additions & 12 deletions lib/rex_cronjob_neues_sync.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

use FriendsOfRedaxo\Neues\Author;
use FriendsOfRedaxo\Neues\Category;
use FriendsOfRedaxo\Neues\Entry;

class rex_cronjob_neues_sync extends rex_cronjob
{
private $rest_urls = ['category' => '/rest/neues/category/5.0.0/',
Expand Down Expand Up @@ -28,15 +32,14 @@ public function execute()
$data[$type] = json_decode($response->getBody(), true);
}

if(isset($data['category']['data'])) {

if (isset($data['category']['data'])) {
foreach ($data['category']['data'] as $category) {
$category = $category['attributes'];

// Überprüfe, ob UUID bereits in der Datenbank vorhanden ist
$neues_category = FriendsOfRedaxo\Neues\Category::query()->where('uuid', $category['uuid'])->findOne();
$neues_category = Category::query()->where('uuid', $category['uuid'])->findOne();
if (null === $neues_category) {
$neues_category = FriendsOfRedaxo\Neues\Category::create();
$neues_category = Category::create();
}

$neues_category->setValue('uuid', $category['uuid']);
Expand All @@ -51,15 +54,14 @@ public function execute()
}
}

if(isset($data['author']['data'])) {

if (isset($data['author']['data'])) {
foreach ($data['author']['data'] as $author) {
$author = $author['attributes'];

// Überprüfe, ob UUID bereits in der Datenbank vorhanden ist
$neues_author = FriendsOfRedaxo\Neues\Author::query()->where('uuid', $author['uuid'])->findOne();
$neues_author = Author::query()->where('uuid', $author['uuid'])->findOne();
if (null === $neues_author) {
$neues_author = FriendsOfRedaxo\Neues\Author::create();
$neues_author = Author::create();
}

$neues_author->setValue('uuid', $author['uuid']);
Expand All @@ -73,12 +75,11 @@ public function execute()
foreach ($data['entry']['data'] as $entry) {
$entry = $entry['attributes'];
// Überprüfe, ob UUID bereits in der Datenbank vorhanden ist
$neues_entry = FriendsOfRedaxo\Neues\Entry::query()->where('uuid', $entry['uuid'])->findOne();
$neues_entry = Entry::query()->where('uuid', $entry['uuid'])->findOne();
if (null === $neues_entry) {
$neues_entry = FriendsOfRedaxo\Neues\Entry::create();
$neues_entry = Entry::create();
}


$neues_entry->setValue('uuid', $entry['uuid']);
$neues_entry->setValue('name', $entry['name']);
$neues_entry->setValue('teaser', $entry['teaser']);
Expand Down Expand Up @@ -127,6 +128,6 @@ public function getParamFields()
],
];

return $fields;
return $fields;
}
}

0 comments on commit d6db739

Please sign in to comment.