Skip to content

Commit

Permalink
Implemented a callback for uploaded files
Browse files Browse the repository at this point in the history
  • Loading branch information
jenwachter committed Oct 22, 2020
1 parent 176654f commit c6281bd
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/AkamaiRsync.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function __construct($settings = array())
// akamai api auth
$this->api_auth = $settings["api_auth"];

$this->callback = $settings['callback'] ?? null;
$this->database = $settings['database'] ?? null;

$this->addFunctions();
Expand All @@ -49,14 +50,16 @@ public function upload(\GearmanJob $job)

// rsync each file separatly

foreach ($workload->filenames as $filename) {
foreach ($workload->filenames as $index => $filename) {
// Fixes bash command for files with single quotes
// See: https://stackoverflow.com/a/1250279
$sanitized = str_replace("'", '\'"\'"\'', $filename);
$command = "cd {$workload->homepath} && rsync -az --relative '{$workload->source}/{$sanitized}' {$this->username}@{$this->akamai_host}::{$this->username}/{$this->directory} 2>&1 > /dev/null";

$run = exec($command, $output, $return);

if ($return) {
// fail
$event = $this->logger->addWarning("Failed to rsync file to Akamai net storage.", array(
"rsync_error" => $return,
"handle" => $handle,
Expand All @@ -80,6 +83,9 @@ public function upload(\GearmanJob $job)
':handle' => $handle
]);
}
if ($this->callback && isset($workload->urls)) {
call_user_func_array([$this->callback, 'onUpload'], [$filename, $workload->urls[$index], $workload->type ?? null]);
}
}
}
}
Expand Down

0 comments on commit c6281bd

Please sign in to comment.