Skip to content

New step remove sftp file #952

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: MOODLE_401_STABLE
Choose a base branch
from
Open

Conversation

gbarat87
Copy link
Contributor

@gbarat87 gbarat87 commented Mar 31, 2025

image

This step is to remove a file from the sftp server.
This is needed as there is no possibility to move a file from a folder to another in the sftp server.
The step "sftp copy file" following by this new one can allows one to move a file around.

@gbarat87 gbarat87 changed the base branch from MOODLE_405_STABLE to MOODLE_401_STABLE March 31, 2025 03:30
@gbarat87 gbarat87 force-pushed the new-step-move-sftp branch 3 times, most recently from 4cdb88d to 69241a1 Compare March 31, 2025 04:09
Copy link
Contributor

@matthewhilton matthewhilton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this also have unit tests added? e.g. see https://github.com/catalyst/moodle-tool_dataflows/blob/MOODLE_405_STABLE/tests/tool_dataflows_sftp_test.php
Since there's no actual SFTP to test against, it might just end up being a test for 1. sanity check that step loads properly, and 2. testing that source is always a remote, and errors otherwise

Comment on lines 37 to 38


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty space

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been removed

if ($sourceisremote) {
$this->delete_from_remote($sftp, $sourcepath);
return $input;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the source isn't a remote, it should throw an exception here. Because it's validated at form validation time, if this is not a remote here it means something is very wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An exception has been raised here

@@ -158,6 +158,7 @@
$string['step_name_connector_set_variable'] = 'Set variable';
$string['step_name_connector_set_multiple_variables'] = 'Set multiple variables';
$string['step_name_connector_sftp'] = 'SFTP file copy';
$string['step_name_connector_sftp_delete_file'] = 'SFTP file to delete';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be SFTP delete file instead ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been rewritten

$hasremote = $sourceremote || $targetremote;
}
if (!$hasremote) {
$errormsg = get_string('connector_sftp:missing_remote', 'tool_dataflows', null, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lang string outputs as At least one of source/target must be remote. but there is only one field for the delete step - it might need another string for just Source must be remote.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The text has been updated for delete and rename

$mform->addElement('static', 'config_source_desc', '', get_string('connector_sftp:source_desc', 'tool_dataflows').
\html_writer::nonempty_tag(
'pre',
get_string('connector_sftp:path_example', 'tool_dataflows').
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a different lang string, this one is currently:


Path to the source file. This can be a local file or remote path e.g.

    sftp://file/path  # Any remote file url;
    out.csv           # A path relative to the flows temp working dir;
    /var/data.json    # An absolute path;
    file:///my/in.txt # Any valid php stream url;

but in the case of this step, only sftp://file/path is valid

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, Source is probably not the most ideal word, File to delete might fit better ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part has been updated

$errors['config_source'] = $errors['config_source'] ?? $errormsg;
}
} else {
if (!empty($config->source) && !empty($config->target)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this care about $config->target at all? It's not shown as a mform element

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this part is in the behavior "copy" so we do need the target here

@matthewhilton
Copy link
Contributor

matthewhilton commented Apr 1, 2025

Another thought - could this also be added as a flow step just for consistency - you should be able to share most of the functionality with the trait

@gbarat87
Copy link
Contributor Author

gbarat87 commented Apr 9, 2025

@matthewhilton Thank you for the review.
After testing, I ave decided to simply add the step "rename" to allow to rename a file in the sftp server. That is making the move easier.
I decided to keep the delete step as it can be useful as well.
All the methods have been moved to a trait to reuse the same code.

@gbarat87 gbarat87 force-pushed the new-step-move-sftp branch from 323bed9 to e657c3d Compare May 19, 2025 06:06
@gbarat87 gbarat87 force-pushed the new-step-move-sftp branch from e657c3d to c2c4e61 Compare May 19, 2025 07:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants