Skip to content

Commit

Permalink
changed: updated for Elgg 6
Browse files Browse the repository at this point in the history
  • Loading branch information
jeabakker committed May 14, 2024
1 parent e3d64b9 commit 9772f91
Show file tree
Hide file tree
Showing 17 changed files with 46 additions and 52 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
10 changes: 5 additions & 5 deletions classes/CSVExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions classes/ColdTrick/CSVExporter/Cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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;
}

Expand Down
15 changes: 4 additions & 11 deletions classes/ColdTrick/CSVExporter/ExportableValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 '';
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"issues": "https://github.com/ColdTrick/csv_exporter/issues"
},
"conflict": {
"elgg/elgg": "<5.1"
"elgg/elgg": "<6.0"
}
}
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion elgg-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[
'type' => 'object',
'subtype' => 'csv_export',
'class' => CSVExport::class,
'class' => \CSVExport::class,
'capabilities' => [
'commentable' => false,
],
Expand Down
2 changes: 0 additions & 2 deletions languages/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -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",

Expand Down
2 changes: 0 additions & 2 deletions languages/nl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
9 changes: 5 additions & 4 deletions lib/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* All helper functions for this plugin are bundled here
*/

use Elgg\Database\RiverTable;
use Elgg\Database\Select;

/**
Expand Down Expand Up @@ -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)) {
Expand Down
16 changes: 0 additions & 16 deletions views/default/admin/administer_utilities/csv_exporter.js

This file was deleted.

16 changes: 16 additions & 0 deletions views/default/admin/administer_utilities/csv_exporter.mjs
Original file line number Diff line number Diff line change
@@ -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();
}
});
3 changes: 1 addition & 2 deletions views/default/admin/administer_utilities/csv_exporter.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

elgg_require_js('admin/administer_utilities/csv_exporter');
elgg_import_esm('admin/administer_utilities/csv_exporter');

// add tab menu
echo elgg_view_menu('csv_exporter', [
Expand Down Expand Up @@ -31,6 +31,5 @@
'created_time_upper' => get_input('created_time_upper'),
];
$params = $params + $vars;

echo elgg_view('csv_exporter/preview', $params);
}
2 changes: 1 addition & 1 deletion views/default/forms/csv_exporter/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion views/default/forms/csv_exporter/group.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 1 addition & 1 deletion views/default/object/csv_export.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down

0 comments on commit 9772f91

Please sign in to comment.