Skip to content

Commit

Permalink
update cronjobs - remove namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndr-w committed Jul 16, 2024
1 parent 5fa766a commit 29ac438
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 55 deletions.
7 changes: 2 additions & 5 deletions boot.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@
use rex_csrf_token;
use rex_extension;
use rex_extension_point;
use rex_package;
use rex_plugin;
use rex_url;
use rex_yform_manager_dataset;
use rex_yform_manager_table;
use rex_yform_rest;
use rex_yform_rest_route;

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
4 changes: 1 addition & 3 deletions lib/rex_cronjob_neues_publish.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

namespace FriendsOfRedaxo\Neues;

use rex_cronjob;
use rex_i18n;

Expand All @@ -12,7 +10,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 = Entry::query()->where('status', 0)->where('publishdate', date('Y-m-d'), '<')->find();
$neues_entry_to_publish = FriendsOfRedaxo\Neues\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
103 changes: 56 additions & 47 deletions lib/rex_cronjob_neues_sync.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
<?php

namespace FriendsOfRedaxo\Neues;

use rex_cronjob;
use rex_i18n;
use rex_socket;
use rex_socket_response;

class rex_cronjob_neues_sync extends rex_cronjob
{
private $rest_urls = ['category' => '/rest/neues/category/5.0.0/',
Expand All @@ -23,7 +16,7 @@ public function execute()
$status = $this->getParam('status');

$socket = rex_socket::factoryUrl($url);
$socket->addHeader('Authorization', 'Bearer ' . $token);
$socket->addHeader('token', $token);
/** @var rex_socket_response $response */
$response = $socket->doGet();

Expand All @@ -35,55 +28,67 @@ public function execute()
$data[$type] = json_decode($response->getBody(), true);
}

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

$neues_category->setValue('uuid', $category['uuid']);
$neues_category->setValue('name', $category['name']);
$neues_category->setValue('image', $category['image']);
$neues_category->setValue('status', $status);
$neues_category->setValue('createdate', $category['createdate']);
$neues_category->setValue('createuser', 'cronjob');
$neues_category->setValue('updatedate', $category['updatedate']);
$neues_category->setValue('updateuser', 'cronjob');
$neues_category->save();
}

$neues_category->setValue('uuid', $category['uuid']);
$neues_category->setValue('name', $category['name']);
$neues_category->setValue('image', $category['image']);
$neues_category->setValue('status', $status);
$neues_category->setValue('createdate', $category['createdate']);
$neues_category->setValue('createuser', 'cronjob');
$neues_category->setValue('updatedate', $category['updatedate']);
$neues_category->setValue('updateuser', 'cronjob');
$neues_category->save();
}

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

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

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

$neues_author->setValue('uuid', $author['uuid']);
$neues_author->setValue('name', $author['name']);
$neues_author->setValue('nickname', $author['nickname']);
$neues_author->setValue('text', $author['text']);
$neues_author->save();
}
}

foreach ($data['entry'] as $entry) {
foreach ($data['entry']['data'] as $entry) {
$entry = $entry['attributes'];
// Überprüfe, ob UUID bereits in der Datenbank vorhanden ist
$neues_entry = Entry::query()->where('uuid', $entry['uuid'])->findOne();
$neues_entry = FriendsOfRedaxo\Neues\Entry::query()->where('uuid', $entry['uuid'])->findOne();
if (null === $neues_entry) {
$neues_entry = new Entry();
$neues_entry = FriendsOfRedaxo\Neues\Entry::create();
}


$neues_entry->setValue('uuid', $entry['uuid']);
$neues_entry->setValue('title', $entry['title']);
$neues_entry->setValue('name', $entry['name']);
$neues_entry->setValue('teaser', $entry['teaser']);
$neues_entry->setValue('description', $entry['description']);
$neues_entry->setValue('url', $entry['url']);
// $neues_entry->setValue('image', $entry['image']);
// $neues_entry->setValue('images', $entry['images']);
$neues_entry->setValue('lang_id', $entry['lang_id']);
$neues_entry->setValue('category_id', $entry['category_id']);
$neues_entry->setValue('author_id', $entry['author_id']);
$neues_entry->setValue('image', $entry['image']);
$neues_entry->setValue('images', $entry['images']);
// $neues_entry->setValue('lang_id', $entry['lang_id']);
// $neues_entry->setValue('category_id', $entry['category_id']);
// $neues_entry->setValue('author_id', $entry['author_id']);
$neues_entry->setValue('status', $status);
$neues_entry->setValue('publishdate', $entry['publishdate']);
$neues_entry->setValue('domain_ids', 0);
Expand All @@ -93,6 +98,8 @@ public function execute()
$neues_entry->setValue('updatedate', $entry['updatedate']);
$neues_entry->save();
}
$this->setMessage(sprintf(rex_i18n::msg('neues_entry_sync_success'), $response->getStatusCode()));
return true;
}

public function getTypeName()
Expand All @@ -102,22 +109,24 @@ public function getTypeName()

public function getParamFields()
{
return [
$fields = [
[
'label' => rex_i18n::msg('neues_entry_sync_cronjob_url'),
'name' => 'url',
'label' => rex_i18n::msg('neues_entry_sync_cronjob_url'),
'type' => 'text',
],
[
'label' => rex_i18n::msg('neues_entry_sync_cronjob_token'),
'name' => 'token',
'label' => rex_i18n::msg('neues_entry_sync_cronjob_token'),
'type' => 'text',
],
[
'label' => rex_i18n::msg('neues_entry_sync_cronjob_status'),
'name' => 'status',
'label' => rex_i18n::msg('neues_entry_sync_cronjob_status'),
'type' => 'text',
],
];

return $fields;
}
}

0 comments on commit 29ac438

Please sign in to comment.