Skip to content

Commit

Permalink
Merge pull request #92 from FriendsOfREDAXO/cb-3
Browse files Browse the repository at this point in the history
Installation und Deinstallation überarbeitet
  • Loading branch information
alxndr-w authored Aug 21, 2024
2 parents 0d144d5 + 0e4e051 commit f7f6e6b
Show file tree
Hide file tree
Showing 8 changed files with 311 additions and 52 deletions.
91 changes: 58 additions & 33 deletions install.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,87 +2,112 @@

namespace FriendsOfRedaxo\Neues;

use FriendsOfRedaxo\Neues\Cronjob\Publish;
use rex;
use rex_addon;
use rex_article;
use rex_config;
use rex_file;
use rex_media;
use rex_media_service;
use rex_path;
use rex_sql;
use rex_yform_manager_table_api;
use Url\Cache;
use Url\Profile;

use function count;
/** @var rex_addon $this */

$sql = rex_sql::factory();

/* Tablesets aktualisieren */
if (rex_plugin::get('yform', 'manager')->isAvailable()) {
rex_yform_manager_table_api::importTablesets(rex_file::get(__DIR__ . '/install/tableset.json'));
/**
* Tablesets aktualisieren
* - Datenbanktabellen anlegen bzw. das Schema aktualisieren
* - YForm-Tablesets eintragen bzw. aktualisieren (soweit das möglich ist)
* - bei vorhandenen Datensätzen ggf. leere UUIDs füllen.
*/
$this->includeFile(__DIR__ . '/install/update_scheme.php');

// Vorhandene leere UUID-Felder aktualisieren
$sql->setQuery('UPDATE ' . rex::getTable('neues_author') . ' SET uuid = uuid() WHERE uuid IS NULL OR uuid = ""');
$sql->setQuery('UPDATE ' . rex::getTable('neues_category') . ' SET uuid = uuid() WHERE uuid IS NULL OR uuid = ""');
$sql->setQuery('UPDATE ' . rex::getTable('neues_entry') . ' SET uuid = uuid() WHERE uuid IS NULL OR uuid = ""');
rex_yform_manager_table_api::importTablesets(rex_file::get(__DIR__ . '/install/tableset.json', '[]'));

require_once __DIR__ . '/install/update_scheme.php';
}
$sql->setQuery('UPDATE ' . rex::getTable('neues_author') . ' SET uuid = uuid() WHERE uuid IS NULL OR uuid = ""');
$sql->setQuery('UPDATE ' . rex::getTable('neues_category') . ' SET uuid = uuid() WHERE uuid IS NULL OR uuid = ""');
$sql->setQuery('UPDATE ' . rex::getTable('neues_entry') . ' SET uuid = uuid() WHERE uuid IS NULL OR uuid = ""');

if (null === rex_media::get('neues_entry_fallback_image.png')) {
rex_file::copy(__DIR__ . '/install/neues_entry_fallback_image.png', rex_path::media('neues_entry_fallback_image.png'));
/**
* Fallback-Image bereitstellen falls noch nicht in der Mediathek.
*/
$fallbackImage = 'neues_entry_fallback_image.png';
if (null === rex_media::get($fallbackImage)) {
rex_file::copy(__DIR__ . '/install/' . $fallbackImage, rex_path::media($fallbackImage));
$data = [];
$data['title'] = 'Aktuelles - Fallback-Image';
$data['category_id'] = 0;
$data['file'] = [
'name' => 'neues_entry_fallback_image.png',
'path' => rex_path::media('neues_entry_fallback_image.png'),
'name' => $fallbackImage,
'path' => rex_path::media($fallbackImage),
];

rex_media_service::addMedia($data, false);
}

/* Cronjob installieren */
if (rex_addon::get('cronjob')->isAvailable()) {
$cronjobPublish = 'FriendsOfRedaxo\\Neues\\Cronjob\\Publish';
/**
* für nachfolgende $this->includeFile.
*/
$subScriptParams = ['sql' => $sql, 'installUser' => 'neues'];

/**
* Optional: Cronjob installieren falls das Cronjob-Addon aktiviert ist.
*/
if (rex_addon::get('cronjob')->isAvailable()) {
/**
* ggf Update von früheren Versionen mit dem alten Klassennamen
* -> rex_cronjob_neues_publish ändern in FriendsOfRedaxo\Neues\Cronjob\Publish.
*/
$sql->setTable(rex::getTable('cronjob'));
$sql->setValue('type', $cronjobPublish);
$sql->setValue('type', Publish::class);
$sql->setWhere('`type` = :class', [':class' => 'rex_cronjob_neues_publish']);
$sql->update();

/**
* Fehlenden CronJob eintragen.
*/
$sql = rex_sql::factory();
$sql->setTable(rex::getTable('cronjob'));
$sql->setWhere('`type` = :class', [':class' => $cronjobPublish]);
$sql->setWhere('`type` = :class', [':class' => Publish::class]);
$sql->select();

if (0 === $sql->getRows()) {
$query = rex_file::get(__DIR__ . '/install/rex_cronjob_neues_publish.sql');
rex_sql::factory()->setQuery($query);
$this->includeFile(__DIR__ . '/install/cronjob_publish.php', $subScriptParams);
}
}

/* URL-Profile installieren */
/**
* Optional: URL-Profile installieren falls das Url-Addon aktiviert ist
* Nach einer erfolgreichen Installation wird in der Config ein Flag gesetzt
* um eine erneute Installation zu vermeiden
* (rex_config::set('neues', 'url_profile', true)).
*/
if (rex_addon::get('url')->isAvailable()) {
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 (0 < count($rex_neues_category)) {
$query = str_replace('999999', (string) rex_article::getSiteStartArticleId(), rex_file::get(__DIR__ . '/install/rex_url_profile_neues_category.sql'));
rex_sql::factory()->setQuery($query);
$urlProfileTable = rex::getTable(Profile::TABLE_NAME);
// Category
$sql->setTable($urlProfileTable);
$sql->setWhere('table_name = :tn', [':tn' => '1_xxx_rex_neues_category']);
$sql->select();
if (0 === $sql->getRows()) {
$this->includeFile(__DIR__ . '/install/url_profile_category.php', $subScriptParams);
}
$rex_neues_entry = array_filter(rex_sql::factory()->getArray("SELECT * FROM rex_url_generator_profile WHERE `table_name` = '1_xxx_rex_neues_entry'"));
if (0 < count($rex_neues_entry)) {
$query = str_replace('999999', (string) rex_article::getSiteStartArticleId(), rex_file::get(__DIR__ . '/install/rex_url_profile_neues_entry.sql'));
rex_sql::factory()->setQuery($query);

// Entry
$sql->setTable($urlProfileTable);
$sql->setWhere('table_name = :tn', [':tn' => '1_xxx_rex_neues_entry']);
$sql->select();
if (0 === $sql->getRows()) {
$this->includeFile(__DIR__ . '/install/url_profile_entry.php', $subScriptParams);
}
/* URL-Profile wurden bereits einmal installiert, daher nicht nochmals installieren und Entwickler-Einstellungen respektieren */

Cache::deleteProfiles();

// URL-Profile als installiert markieren
rex_config::set('neues', 'url_profile', true);
}
}
35 changes: 35 additions & 0 deletions install/cronjob_publish.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/**
* Job "Publish" konfigurieren.
*
* @var rex_sql $sql Kommt aus dem aufrufenden install.php
* @var string $installUser Kommt aus dem aufrufenden install.php
*/

use FriendsOfRedaxo\Neues\Cronjob\Publish;

$job_intervall = [
'minutes' => 'all',
'hours' => 'all',
'days' => 'all',
'weekdays' => 'all',
'month' => 'all',
];

$timestamp = rex_cronjob_manager_sql::calculateNextTime($job_intervall);

$sql->setTable(rex::getTable('cronjob'));
$sql->setValue('name', '[neues] Geplante Beiträge veröffentlichen');
$sql->setValue('description', 'Veröffentlicht alle Beiträge (status = 1), deren Status geplant (status = 0) ist und deren Veröffentlichungszeitpunkt erreicht wurde (publishdate < now()).');
$sql->setValue('type', Publish::class);
$sql->setValue('parameters', '[]');
$sql->setValue('interval', json_encode($job_intervall));
$sql->setValue('nexttime', rex_sql::datetime($timestamp));
$sql->setValue('environment', '|frontend|backend|script|');
$sql->setValue('execution_moment', 0);
$sql->setValue('execution_start', '0000-00-00 00:00:00');
$sql->setValue('status', 1);
$sql->addGlobalUpdateFields($installUser);
$sql->addGlobalCreateFields($installUser);
$sql->insert();
4 changes: 0 additions & 4 deletions install/rex_cronjob_neues_publish.sql

This file was deleted.

4 changes: 0 additions & 4 deletions install/rex_url_profile_neues_category.sql

This file was deleted.

4 changes: 0 additions & 4 deletions install/rex_url_profile_neues_entry.sql

This file was deleted.

59 changes: 59 additions & 0 deletions install/url_profile_category.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

/**
* URL-Addon-Profil für Category.
*
* @var rex_sql $sql
* @var string $installUser Kommt aus dem aufrufenden install.php
*/

$sql->setTable(rex::getTable('url_generator_profile'));
$sql->setValue('namespace', 'neues-category-id');
$sql->setValue('article_id', rex_article::getSiteStartArticleId());
$sql->setValue('clang_id', 1);
$sql->setValue('ep_pre_save_called', 0);
$sql->setValue('table_name', '1_xxx_rex_neues_category');
$sql->setValue('table_parameters', json_encode([
'column_id' => 'id',
'column_clang_id' => '',
'restriction_1_column' => 'status',
'restriction_1_comparison_operator' => '>',
'restriction_1_value' => '0',
'restriction_2_logical_operator' => '',
'restriction_2_column' => '',
'restriction_2_comparison_operator' => '=',
'restriction_2_value' => '',
'restriction_3_logical_operator' => '',
'restriction_3_column' => '',
'restriction_3_comparison_operator' => '=',
'restriction_3_value' => '',
'column_segment_part_1' => 'name',
'column_segment_part_2_separator' => '/',
'column_segment_part_2' => '',
'column_segment_part_3_separator' => '/',
'column_segment_part_3' => '',
'relation_1_column' => '',
'relation_1_position' => 'BEFORE',
'relation_2_column' => '',
'relation_2_position' => 'BEFORE',
'relation_3_column' => '',
'relation_3_position' => 'BEFORE',
'append_user_paths' => '',
'append_structure_categories' => '0',
'column_seo_title' => 'name',
'column_seo_description' => '',
'column_seo_image' => '',
'sitemap_add' => '1',
'sitemap_frequency' => 'weekly',
'sitemap_priority' => '0.5',
'column_sitemap_lastmod' => '',
]));
$sql->setValue('relation_1_table_name', '');
$sql->setValue('relation_1_table_parameters', '[]');
$sql->setValue('relation_2_table_name', '');
$sql->setValue('relation_2_table_parameters', '[]');
$sql->setValue('relation_3_table_name', '');
$sql->setValue('relation_3_table_parameters', '[]');
$sql->addGlobalCreateFields($installUser);
$sql->addGlobalUpdateFields($installUser);
$sql->insert();
58 changes: 58 additions & 0 deletions install/url_profile_entry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/**
* URL-Addon-Profil für Entry.
*
* @var rex_sql $sql
* @var string $installUser Kommt aus dem aufrufenden install.php
*/
$sql->setTable(rex::getTable('url_generator_profile'));
$sql->setValue('namespace', 'neues-entry-id');
$sql->setValue('article_id', rex_article::getSiteStartArticleId());
$sql->setValue('clang_id', 1);
$sql->setValue('ep_pre_save_called', 0);
$sql->setValue('table_name', '1_xxx_rex_neues_entry');
$sql->setValue('table_parameters', json_encode([
'column_id' => 'id',
'column_clang_id' => '',
'restriction_1_column' => 'status',
'restriction_1_comparison_operator' => '>',
'restriction_1_value' => '0',
'restriction_2_logical_operator' => '',
'restriction_2_column' => '',
'restriction_2_comparison_operator' => '=',
'restriction_2_value' => '',
'restriction_3_logical_operator' => '',
'restriction_3_column' => '',
'restriction_3_comparison_operator' => '=',
'restriction_3_value' => '',
'column_segment_part_1' => 'name',
'column_segment_part_2_separator' => '/',
'column_segment_part_2' => '',
'column_segment_part_3_separator' => '/',
'column_segment_part_3' => '',
'relation_1_column' => '',
'relation_1_position' => 'BEFORE',
'relation_2_column' => '',
'relation_2_position' => 'BEFORE',
'relation_3_column' => '',
'relation_3_position' => 'BEFORE',
'append_user_paths' => '',
'append_structure_categories' => '0',
'column_seo_title' => 'name',
'column_seo_description' => 'teaser',
'column_seo_image' => 'image',
'sitemap_add' => '1',
'sitemap_frequency' => 'daily',
'sitemap_priority' => '0.7',
'column_sitemap_lastmod' => 'updatedate',
]));
$sql->setValue('relation_1_table_name', '');
$sql->setValue('relation_1_table_parameters', '[]');
$sql->setValue('relation_2_table_name', '');
$sql->setValue('relation_2_table_parameters', '[]');
$sql->setValue('relation_3_table_name', '');
$sql->setValue('relation_3_table_parameters', '[]');
$sql->addGlobalCreateFields($installUser);
$sql->addGlobalUpdateFields($installUser);
$sql->insert();
Loading

0 comments on commit f7f6e6b

Please sign in to comment.