Skip to content

Commit

Permalink
FTPSyncfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
winnidat authored and dasistwas committed Oct 12, 2023
1 parent 9448729 commit 6ad0dcb
Show file tree
Hide file tree
Showing 15 changed files with 594 additions and 6 deletions.
67 changes: 67 additions & 0 deletions classes/event/cron_trigger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
// This file is part of mod_datalynx for Moodle - http://moodle.org/
//
// It is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// It is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* The mod_datalynx comment created event.
*
* @package mod_datalynx
* @copyright 2023 Thomas Winkler
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace mod_datalynx\event;

defined('MOODLE_INTERNAL') or die();

/**
* The mod_datalynx comment created event class.
*
* @package mod_datalynx
* @since Moodle 4.0
* @copyright 2023 Thomas Winkler
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class cron_trigger extends \core\event\base {

/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['objecttable'] = 'datalynx';
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_OTHER;
}

/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('datalynx_cron_trigger', 'mod_datalynx');
}

/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "Cron Job trigger occured";
}
}
57 changes: 57 additions & 0 deletions classes/task/cron_trigger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Trigger an event in a periodic time
*
* @package mod_datalynx
* @copyright 2023 Thomas Winkler
* @author Thomas Winkler
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_datalynx\task;

defined('MOODLE_INTERNAL') || die();

/**
* Trigger an event in a periodic time
*
* @package mod_datalynx
* @copyright 2023 Thomas Winkler
* @author Thomas Winkler
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
*/
class cron_trigger extends \core\task\scheduled_task {

public function get_name() {
return get_string('cron_trigger', 'mod_datalynx');
}

/**
*
* Close off any overdue attempts.
*/
public function execute() {
global $DB;
$records = $DB->get_records('datalynx_rules', null, '', 'DISTINCT dataid');
foreach ($records as $record) {
$df = new \mod_datalynx\datalynx($record->dataid);
$event = \mod_datalynx\event\cron_trigger::create(array('context' => $df->context, 'objectid' => $df->id()));
$event->trigger();
}
}
}
4 changes: 4 additions & 0 deletions db/events.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,9 @@
array('eventname' => 'mod_datalynx\event\team_updated',
'callback' => 'datalynx_rule_manager::trigger_rules',
'includefile' => 'mod/datalynx/rule/rule_manager.php'
),
array('eventname' => 'mod_datalynx\event\cron_trigger',
'callback' => 'datalynx_rule_manager::trigger_rules',
'includefile' => 'mod/datalynx/rule/rule_manager.php'
)
);
38 changes: 38 additions & 0 deletions db/tasks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Definition of Quiz scheduled tasks.
*
* @package mod _datalynx
* @category task
* @copyright 2023 Thomas Winkler Michael Hughes <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

$tasks = [
[
'classname' => 'mod_datalynx\task\cron_trigger',
'blocking' => 0,
'minute' => '*',
'hour' => '*',
'day' => '*',
'dayofweek' => '*',
'month' => '*'
]
];
4 changes: 2 additions & 2 deletions entries_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -507,15 +507,15 @@ public function get_contentinfo(array $fids) {
* Process entries when after editing content for saving into db
*
* @param string $action
* @param string $eids
* @param string||array $eids
* @param null $data
* @param bool $confirmed
* @return array notificationstrings, list of processed ids
* @throws coding_exception
* @throws dml_exception
* @throws moodle_exception
*/
public function process_entries(string $action, string $eids, $data = null, bool $confirmed = false): array {
public function process_entries(string $action, $eids, $data = null, bool $confirmed = false): array {
global $DB, $USER, $OUTPUT, $PAGE;
$dl = $this->datalynx;
$errorstring = '';
Expand Down
11 changes: 9 additions & 2 deletions field/file/field_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ public function update_content(stdClass $entry, array $values = null) {
$rec->entryid = $entryid;
$rec->content1 = $alttext;

if (count($files) > 1) {
// Hack for update field for ftpsync.
if (count($files) > 1 || $filemanager == 111111) {
$rec->content = 1; // We just store a 1 to show there is something, look for files.
} else {
$rec->content = 0; // In case there is no file, add a 0.
Expand Down Expand Up @@ -175,11 +176,17 @@ public function prepare_import_content(&$data, $importsettings, $csvrecord = nul
$fs = get_file_storage();
$fs->create_file_from_url($filerecord, $fileurl, null, true);
}

// If no files, then return false.
if ($filesprocessed == 0) {
if ($filesprocessed == 0 && $data->ftpsyncmode == 0) {
return false;
}

if ($data->ftpsyncmode) {
$data->{"field_{$fieldid}_{$entryid}"} = 1;
$draftitemid = 111111;
}

// Tell the update script what itemid to look for.
$data->{"field_{$fieldid}_{$entryid}_filemanager"} = $draftitemid;

Expand Down
3 changes: 3 additions & 0 deletions lang/de/datalynx.php
Original file line number Diff line number Diff line change
Expand Up @@ -895,3 +895,6 @@
$string['search:entry'] = "Datalynx - Einträge";

$string['noselection'] = "Keine Auswahl";

// Task.
$string['datalynx_cron_trigger'] = "DL Cron Job";
3 changes: 3 additions & 0 deletions lang/en/datalynx.php
Original file line number Diff line number Diff line change
Expand Up @@ -937,3 +937,6 @@
$string['search:entry'] = "Datalynx - entries";

$string['noselection'] = "Nothing selected";

// Task.
$string['datalynx_cron_trigger'] = "DL Cron Job";
32 changes: 32 additions & 0 deletions rule/ftpsyncfiles/lang/de/datalynxrule_ftpsyncfiles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
// This file is part of mod_datalynx for Moodle - http://moodle.org/
//
// It is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// It is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
*
* @package datalynxrule
* @subpackage ftpsyncfiles
* @copyright 2023 Thomas Winkler
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['event'] = 'Datalynx Ereignis';
$string['pluginname'] = 'FTP Sync Data';
$string['triggerspecificevent'] = 'Nur bei markierter Checkbox senden';

$string['sftpsettings'] = 'SFTP Settings';
$string['sftpserver'] = 'STFP Server';
$string['sftpusername'] = 'STFP Username';
$string['sftppassword'] = 'STFP Passwort';
$string['sftppath'] = 'STFP Path';
32 changes: 32 additions & 0 deletions rule/ftpsyncfiles/lang/en/datalynxrule_ftpsyncfiles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
// This file is part of mod_datalynx for Moodle - http://moodle.org/
//
// It is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// It is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
*
* @package datalynxrule
* @subpackage ftpsyncfiles
* @copyright 2023 Thomas Winkler
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['event'] = 'Datalynx event';
$string['pluginname'] = 'FTP Sync Data';
$string['triggerspecificevent'] = 'Nur bei markierter Checkbox senden';

$string['sftpsettings'] = 'SFTP Settings';
$string['sftpserver'] = 'STFP Server';
$string['sftpusername'] = 'STFP Username';
$string['sftppassword'] = 'STFP Password';
$string['sftppath'] = 'STFP Path';
Loading

0 comments on commit 6ad0dcb

Please sign in to comment.