From 9772f91797afda06d0b95df9bc69181f4c9b0ed4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jer=C3=B4me=20Bakker?= Date: Tue, 14 May 2024 16:04:32 +0200 Subject: [PATCH] changed: updated for Elgg 6 --- .github/workflows/phpunit.yml | 4 +++- README.md | 2 +- classes/CSVExport.php | 10 +++++----- classes/ColdTrick/CSVExporter/Cron.php | 6 ++++-- .../ColdTrick/CSVExporter/ExportableValues.php | 15 ++++----------- composer.json | 2 +- composer.lock | 2 +- elgg-plugin.php | 2 +- languages/en.php | 2 -- languages/nl.php | 2 -- lib/functions.php | 9 +++++---- .../admin/administer_utilities/csv_exporter.js | 16 ---------------- .../admin/administer_utilities/csv_exporter.mjs | 16 ++++++++++++++++ .../admin/administer_utilities/csv_exporter.php | 3 +-- views/default/forms/csv_exporter/edit.php | 2 +- views/default/forms/csv_exporter/group.php | 3 ++- views/default/object/csv_export.php | 2 +- 17 files changed, 46 insertions(+), 52 deletions(-) delete mode 100644 views/default/admin/administer_utilities/csv_exporter.js create mode 100644 views/default/admin/administer_utilities/csv_exporter.mjs diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 67fe092..6147873 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -3,6 +3,8 @@ name: PHPUnit Plugin Tests on: [push, pull_request] jobs: - lint: + phpunit: name: Run PHPUnit test suites uses: ColdTrick/.github/.github/workflows/phpunit.yml@master + with: + elgg_major_version: 6 diff --git a/README.md b/README.md index 375a3b0..3541316 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ CSV Exporter ============ -![Elgg 5.1](https://img.shields.io/badge/Elgg-5.1-green.svg) +![Elgg 6.0](https://img.shields.io/badge/Elgg-6.0-green.svg) ![Lint Checks](https://github.com/ColdTrick/csv_exporter/actions/workflows/lint.yml/badge.svg?event=push) [![Latest Stable Version](https://poser.pugx.org/coldtrick/csv_exporter/v/stable.svg)](https://packagist.org/packages/coldtrick/csv_exporter) [![License](https://poser.pugx.org/coldtrick/csv_exporter/license.svg)](https://packagist.org/packages/coldtrick/csv_exporter) diff --git a/classes/CSVExport.php b/classes/CSVExport.php index 2349680..b92c6ba 100644 --- a/classes/CSVExport.php +++ b/classes/CSVExport.php @@ -55,17 +55,17 @@ public function getDisplayName(): string { /** * Get data from the csv configuration * - * @param string $field (optional) the field to get, leave empty for all fields + * @param null|string $field (optional) the field to get, leave empty for all fields * - * @return void|string|array + * @return null|string|array */ - public function getFormData($field = '') { + public function getFormData(string $field = null) { if (!isset($this->form_data)) { $this->form_data = json_decode($this->description, true); } if (empty($this->form_data) || !is_array($this->form_data)) { - return; + return null; } if (empty($field)) { @@ -75,7 +75,7 @@ public function getFormData($field = '') { if ($field === 'type' || $field === 'subtype') { $type_subtype = $this->getFormData('type_subtype'); if (!is_string($type_subtype)) { - return; + return null; } list($type, $subtype) = explode(':', $type_subtype); diff --git a/classes/ColdTrick/CSVExporter/Cron.php b/classes/ColdTrick/CSVExporter/Cron.php index 010aa0b..0b1badc 100644 --- a/classes/ColdTrick/CSVExporter/Cron.php +++ b/classes/ColdTrick/CSVExporter/Cron.php @@ -16,8 +16,10 @@ class Cron { */ public static function processExports(\Elgg\Event $event): void { $time = (int) $event->getParam('time', time()); + /* @var $cron_logger \Elgg\Logger\Cron */ + $cron_logger = $event->getParam('logger'); - elgg_call(ELGG_IGNORE_ACCESS, function () use ($time) { + elgg_call(ELGG_IGNORE_ACCESS, function () use ($time, $cron_logger) { /* @var $batch \ElggBatch */ $batch = elgg_get_entities([ 'type' => 'object', @@ -40,7 +42,7 @@ public static function processExports(\Elgg\Event $event): void { /* @var $csv_export \CSVExport */ foreach ($batch as $csv_export) { if ($csv_export->isProcessing()) { - elgg_log("CSV export '{$csv_export->getDisplayName()}' is already processing: {$csv_export->started}", 'NOTICE'); + $cron_logger->notice("CSV export '{$csv_export->getDisplayName()}' is already processing: {$csv_export->started}"); continue; } diff --git a/classes/ColdTrick/CSVExporter/ExportableValues.php b/classes/ColdTrick/CSVExporter/ExportableValues.php index 3f0a497..59743e5 100644 --- a/classes/ColdTrick/CSVExporter/ExportableValues.php +++ b/classes/ColdTrick/CSVExporter/ExportableValues.php @@ -39,8 +39,6 @@ public static function getExportableValues(\Elgg\Event $event): ?array { elgg_echo('csv_exporter:exportable_value:url') => 'csv_exporter_url', elgg_echo('csv_exporter:exportable_value:access_id') => 'access_id', elgg_echo('csv_exporter:exportable_value:access_id_readable') => 'csv_exporter_access_id_readable', - elgg_echo('csv_exporter:exportable_value:icontime') => 'icontime', - elgg_echo('csv_exporter:exportable_value:icontime_readable') => 'csv_exporter_icontime_readable', elgg_echo('csv_exporter:exportable_value:icon_url:master') => 'csv_exporter_icon_url_master', elgg_echo('csv_exporter:exportable_value:icon_present') => 'csv_exporter_icon_present', ]; @@ -99,9 +97,9 @@ protected static function getUserExportableValues(): array { $profile_fields = elgg()->fields->get('user', 'user'); foreach ($profile_fields as $field) { $metadata_name = $field['name']; - $lan = elgg_extract('#label', $field, $metadata_name); + $label = elgg_extract('#label', $field, $metadata_name); - $result[$lan] = $metadata_name; + $result[$label] = $metadata_name; } // add defaults @@ -135,9 +133,9 @@ protected static function getGroupExportableValues(): array { $profile_fields = elgg()->fields->get('group', 'group'); foreach ($profile_fields as $field) { $metadata_name = $field['name']; - $lan = elgg_extract('#label', $field, $metadata_name); + $label = elgg_extract('#label', $field, $metadata_name); - $result[$lan] = $metadata_name; + $result[$label] = $metadata_name; } // add defaults @@ -234,11 +232,6 @@ public static function exportEntityValue(\Elgg\Event $event) { case 'csv_exporter_access_id_readable': return elgg_get_readable_access_level($entity->access_id); - case 'csv_exporter_icontime_readable': - if (!isset($entity->icontime)) { - return ''; - } - return csv_exported_get_readable_timestamp($entity->icontime); case 'csv_exporter_icon_url_master': if (!$entity->hasIcon('master')) { return ''; diff --git a/composer.json b/composer.json index ae2318b..e7a1e73 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,6 @@ "issues": "https://github.com/ColdTrick/csv_exporter/issues" }, "conflict": { - "elgg/elgg": "<5.1" + "elgg/elgg": "<6.0" } } diff --git a/composer.lock b/composer.lock index f5f596f..91737ad 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b0b10cbb377bd1d8d63bc3b2931fed3f", + "content-hash": "c7a2f6121ec3cad150f08fbccc8ead63", "packages": [], "packages-dev": [], "aliases": [], diff --git a/elgg-plugin.php b/elgg-plugin.php index e94f8ec..2f0bf57 100644 --- a/elgg-plugin.php +++ b/elgg-plugin.php @@ -10,7 +10,7 @@ [ 'type' => 'object', 'subtype' => 'csv_export', - 'class' => CSVExport::class, + 'class' => \CSVExport::class, 'capabilities' => [ 'commentable' => false, ], diff --git a/languages/en.php b/languages/en.php index f66ffed..42f875c 100644 --- a/languages/en.php +++ b/languages/en.php @@ -55,8 +55,6 @@ 'csv_exporter:exportable_value:url' => "Entity URL", 'csv_exporter:exportable_value:access_id' => "Access", 'csv_exporter:exportable_value:access_id_readable' => "Access (readable)", - 'csv_exporter:exportable_value:icontime' => "Icon upload time", - 'csv_exporter:exportable_value:icontime_readable' => "Icon upload time (readable)", 'csv_exporter:exportable_value:icon_url:master' => "Icon url", 'csv_exporter:exportable_value:icon_present' => "Icon present", diff --git a/languages/nl.php b/languages/nl.php index 7280c8c..a4c3c73 100644 --- a/languages/nl.php +++ b/languages/nl.php @@ -11,8 +11,6 @@ 'csv_exporter:menu:entity:restart' => 'Opnieuw verwerken', 'csv_exporter:action:admin:restart:error:not_processing' => 'De CSV Export wordt op dit moment niet verwerkt, herstarten niet mogelijk', 'csv_exporter:action:admin:restart:success' => 'De CSV Export is herstart', - 'csv_exporter:exportable_value:icontime' => 'Icoon upload tijdstip', - 'csv_exporter:exportable_value:icontime_readable' => 'Icoon upload tijdstip (leesbaar)', 'csv_exporter:exportable_value:icon_url:master' => 'Icoon url', 'csv_exporter:exportable_value:icon_present' => 'Icoon aanwezig', 'admin:administer_utilities:csv_exporter:download' => 'Alle CSV exports', diff --git a/lib/functions.php b/lib/functions.php index 6ae79e2..95b3c9e 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -3,6 +3,7 @@ * All helper functions for this plugin are bundled here */ +use Elgg\Database\RiverTable; use Elgg\Database\Select; /** @@ -161,12 +162,12 @@ function csv_exporter_get_exportable_group_values(string $type = 'object', strin * @return int the UNIX timestamp of the latest activity */ function csv_exporter_get_last_group_activity(\ElggGroup $entity): int { - $select = Select::fromTable('river', 'r'); - $entities = $select->joinEntitiesTable('r', 'object_guid'); + $select = Select::fromTable(RiverTable::TABLE_NAME, RiverTable::DEFAULT_JOIN_ALIAS); + $entities = $select->joinEntitiesTable($select->getTableAlias(), 'object_guid'); - $select->addSelect('max(r.posted) as posted') + $select->addSelect("max({$select->getTableAlias()}.posted) as posted") ->where($select->compare("{$entities}.container_guid", '=', $entity->guid, ELGG_VALUE_GUID)) - ->orWhere($select->compare('r.object_guid', '=', $entity->guid, ELGG_VALUE_GUID)); + ->orWhere($select->compare("{$select->getTableAlias()}.object_guid", '=', $entity->guid, ELGG_VALUE_GUID)); $data = elgg()->db->getData($select); if (empty($data)) { diff --git a/views/default/admin/administer_utilities/csv_exporter.js b/views/default/admin/administer_utilities/csv_exporter.js deleted file mode 100644 index 29d475d..0000000 --- a/views/default/admin/administer_utilities/csv_exporter.js +++ /dev/null @@ -1,16 +0,0 @@ -define(['jquery'], function($) { - $(document).on('change', '#csv-exporter-type-subtype', function() { - var $form = $(this).closest('form'); - - $form.find('input[name="preview"]').val(0); - $form.submit(); - }); - - $(document).on('change', '#csv-exporter-time', function() { - if ($(this).val() === 'range') { - $('#csv-exporter-range').closest('.elgg-field').show(); - } else { - $('#csv-exporter-range').closest('.elgg-field').hide(); - } - }); -}); diff --git a/views/default/admin/administer_utilities/csv_exporter.mjs b/views/default/admin/administer_utilities/csv_exporter.mjs new file mode 100644 index 0000000..531fe9d --- /dev/null +++ b/views/default/admin/administer_utilities/csv_exporter.mjs @@ -0,0 +1,16 @@ +import 'jquery'; + +$(document).on('change', '#csv-exporter-type-subtype', function() { + var $form = $(this).closest('form'); + + $form.find('input[name="preview"]').val(0); + $form.submit(); +}); + +$(document).on('change', '#csv-exporter-time', function() { + if ($(this).val() === 'range') { + $('#csv-exporter-range').closest('.elgg-field').show(); + } else { + $('#csv-exporter-range').closest('.elgg-field').hide(); + } +}); diff --git a/views/default/admin/administer_utilities/csv_exporter.php b/views/default/admin/administer_utilities/csv_exporter.php index 8c5e556..ba17991 100644 --- a/views/default/admin/administer_utilities/csv_exporter.php +++ b/views/default/admin/administer_utilities/csv_exporter.php @@ -1,6 +1,6 @@ get_input('created_time_upper'), ]; $params = $params + $vars; - echo elgg_view('csv_exporter/preview', $params); } diff --git a/views/default/forms/csv_exporter/edit.php b/views/default/forms/csv_exporter/edit.php index 208b5e9..5f52f1f 100644 --- a/views/default/forms/csv_exporter/edit.php +++ b/views/default/forms/csv_exporter/edit.php @@ -138,7 +138,7 @@ 'text' => elgg_echo('csv_exporter:admin:schedule'), 'class' => 'elgg-button-action', 'formaction' => elgg_generate_action_url('csv_exporter/edit', [], false), - 'icon' => 'clock-o', + 'icon' => 'clock', ], ], 'align' => 'horizontal', diff --git a/views/default/forms/csv_exporter/group.php b/views/default/forms/csv_exporter/group.php index b02e1f5..dd6d796 100644 --- a/views/default/forms/csv_exporter/group.php +++ b/views/default/forms/csv_exporter/group.php @@ -54,7 +54,8 @@ // form footer $footer = elgg_view_field([ '#type' => 'submit', - 'text' => elgg_echo('save'), + 'icon' => 'clock', + 'text' => elgg_echo('csv_exporter:admin:schedule'), ]); elgg_set_form_footer($footer); diff --git a/views/default/object/csv_export.php b/views/default/object/csv_export.php index 900d98c..539357f 100644 --- a/views/default/object/csv_export.php +++ b/views/default/object/csv_export.php @@ -15,7 +15,7 @@ ]; } elseif ($entity->isScheduled()) { $imprint[] = [ - 'icon_name' => 'clock-o', + 'icon_name' => 'clock', 'content' => elgg_echo('csv_exporter:object:csv_export:scheduled'), ]; } elseif ($entity->isCompleted()) {