Skip to content

Commit

Permalink
changed: moved class and action registration to elgg-plugin.php
Browse files Browse the repository at this point in the history
  • Loading branch information
jeabakker committed Apr 13, 2018
1 parent d8ced7b commit f38cf46
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 40 deletions.
16 changes: 7 additions & 9 deletions actions/edit.php → actions/csv_exporter/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,25 @@

$guid = (int) get_input('guid');
if (!empty($guid)) {
elgg_entity_gatekeeper($guid, 'object', CSVExport::SUBTYPE);

/* @var $entity CSVExport */
$entity = get_entity($guid);
if (!$entity instanceof CSVExport || !$entity->canEdit()) {
return elgg_error_response(elgg_echo('actionunauthorized'));
}
} else {
$entity = new CSVExport();
}

$form_fields = elgg_get_sticky_values('csv_exporter');

// save all the form data
$entity->title = get_input('title');
$entity->title = elgg_get_title_input();
$entity->description = json_encode($form_fields);

// schedule the export for processing
$entity->scheduled = time();

if ($entity->save()) {
system_message(elgg_echo('csv_exporter:action:edit:success'));
} else {
register_error(elgg_echo('save:fail'));
if (!$entity->save()) {
return elgg_error_response(elgg_echo('save:fail'));
}

forward(REFERER);
return elgg_ok_response('', elgg_echo('csv_exporter:action:edit:success'));
10 changes: 0 additions & 10 deletions activate.php

This file was deleted.

19 changes: 7 additions & 12 deletions classes/CSVExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,22 +181,17 @@ public function process() {
'type' => $type,
'subtype' => $subtype,
'limit' => false,
'batch' => true,
];

// limit users to members of the site
if ($type == 'user') {
$entity_options['relationship'] = 'member_of_site';
$entity_options['relationship_guid'] = elgg_get_site_entity()->getGUID();
$entity_options['inverse_relationship'] = true;
}

// add time constraints
$this->addTimeContraints($entity_options);

// this could take a while
set_time_limit(0);

$entities = new ElggBatch('elgg_get_entities_from_relationship', $entity_options);
/* @var $entities ElggBatch */
$entities = elgg_get_entities($entity_options);
/* @var $entity ElggEntity */
foreach ($entities as $entity) {

Expand Down Expand Up @@ -260,7 +255,7 @@ protected function unlockProcessing() {
*/
protected function getFileObject() {

if (!$this->getGUID()) {
if (!$this->guid) {
return false;
}

Expand All @@ -271,9 +266,9 @@ protected function getFileObject() {
}

$fh = new ElggFile();
$fh->owner_guid = $this->getGUID();
$fh->owner_guid = $this->guid;

$fh->setFilename($filename . '.csv');
$fh->setFilename("{$filename}.csv");

return $fh;
}
Expand Down Expand Up @@ -351,7 +346,7 @@ protected function complete() {

$subject = elgg_echo('csv_exporter:notify:complete:subject', [$title]);
$message = elgg_echo('csv_exporter:notify:complete:message', [
$owner->name,
$owner->getDisplayName(),
$title,
$admin_link,
]);
Expand Down
6 changes: 0 additions & 6 deletions deactivate.php

This file was deleted.

16 changes: 16 additions & 0 deletions elgg-plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

return [
'entities' => [
[
'type' => 'object',
'subtype' => CSVExport::SUBTYPE,
'class' => CSVExport::class,
],
],
'actions' => [
'csv_exporter/edit' => [
'access' => 'admin',
],
],
];
3 changes: 0 additions & 3 deletions start.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,4 @@ function csv_exporter_init() {

// events
elgg_register_event_handler('upgrade', 'system', '\ColdTrick\CSVExporter\Upgrade::setClassHandler');

// register actions
elgg_register_action('csv_exporter/edit', dirname(__FILE__) . '/actions/edit.php', 'admin');
}

0 comments on commit f38cf46

Please sign in to comment.