Skip to content
Snippets Groups Projects
Commit cfd8d226 authored by Borut Piletic's avatar Borut Piletic
Browse files

Add file limit support.

parent ab741f28
No related branches found
No related tags found
1 merge request!3Add file limit support
...@@ -27,6 +27,7 @@ class FTPBatch implements BatchInterface { ...@@ -27,6 +27,7 @@ class FTPBatch implements BatchInterface {
$file_list = $client->list($params['source_path']); $file_list = $client->list($params['source_path']);
$total = count($file_list); $total = count($file_list);
$file_limit = $params['file_limit'] ?? 0;
$files_to_process = []; $files_to_process = [];
$i = 0; $i = 0;
foreach ($file_list as $file) { foreach ($file_list as $file) {
...@@ -43,6 +44,10 @@ class FTPBatch implements BatchInterface { ...@@ -43,6 +44,10 @@ class FTPBatch implements BatchInterface {
]); ]);
$files_to_process = []; $files_to_process = [];
} }
if ($file_limit && $i >= $file_limit) {
break;
}
} }
batch_set($batchBuilder->toArray()); batch_set($batchBuilder->toArray());
......
...@@ -86,13 +86,17 @@ class FTPBatchForm extends FormBase { ...@@ -86,13 +86,17 @@ class FTPBatchForm extends FormBase {
$settings = $operation->getPluginSettings(); $settings = $operation->getPluginSettings();
$form['actions']['#type'] = 'actions'; $form['actions']['#type'] = 'actions';
$form['descriptions'] = [ $form['description'] = [
'#markup' => $this->t('Connect to FTP server <b>%host</b> and transfer files from <b>%source</b> to <b>%destination</b>', [ '#markup' => $this->t('Connect to FTP server <b>%host</b> and transfer files from <b>%source</b> to <b>%destination</b>', [
'%host' => $settings['hostname'], '%host' => $settings['hostname'],
'%source' => $settings['source_path'], '%source' => $settings['source_path'],
'%destination' => $settings['destination_path'], '%destination' => $settings['destination_path'],
]), ]),
]; ];
if ($settings['file_limit']) {
$form['description']['#markup'] .= '<br>';
$form['description']['#markup'] .= $this->t('<b>Transfer is limited to %limit of files.</b>', ['%limit' => $settings['file_limit']]);
}
$form['actions']['submit'] = [ $form['actions']['submit'] = [
'#type' => 'submit', '#type' => 'submit',
'#value' => $this->t('Transfer'), '#value' => $this->t('Transfer'),
......
...@@ -160,6 +160,12 @@ class FTPDirectorySync extends OperationPluginBase { ...@@ -160,6 +160,12 @@ class FTPDirectorySync extends OperationPluginBase {
'#description' => $this->t('Number of files to transfer per batch.'), '#description' => $this->t('Number of files to transfer per batch.'),
'#default_value' => $settings['batch_size'] ?? 10, '#default_value' => $settings['batch_size'] ?? 10,
]; ];
$form['file_limit'] = [
'#type' => 'number',
'#title' => $this->t('Transfter file limit'),
'#description' => $this->t('Limit the number of files to be transfered. After exceeding the limit the operation will stop. <br>This is only useful for testing purposes. <strong>Defaults to "0" which means all files will be downloaded</strong>.'),
'#default_value' => $settings['file_limit'] ?? 0,
];
$form['batch'] = [ $form['batch'] = [
'#type' => 'link', '#type' => 'link',
'#title' => $this->t('Transfer FTP files'), '#title' => $this->t('Transfer FTP files'),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment