@@ -40,6 +40,12 @@ discard block |
||
| 40 | 40 | **********************/ |
| 41 | 41 | |
| 42 | 42 | // Start FFmpeg for output transcoding |
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @param string $tmpPathInput |
|
| 46 | + * @param null|string $pathToInputFile |
|
| 47 | + * @param string $pathToOutputFiles |
|
| 48 | + */ |
|
| 43 | 49 | public function transcode_asset( |
| 44 | 50 | $tmpPathInput, |
| 45 | 51 | $pathToInputFile, |
@@ -594,6 +600,10 @@ discard block |
||
| 594 | 600 | */ |
| 595 | 601 | |
| 596 | 602 | // Execute FFMpeg to get video information |
| 603 | + |
|
| 604 | + /** |
|
| 605 | + * @param string|null $pathToInputFile |
|
| 606 | + */ |
|
| 597 | 607 | public function get_asset_info($pathToInputFile) |
| 598 | 608 | { |
| 599 | 609 | $pathToInputFile = escapeshellarg($pathToInputFile); |
@@ -47,11 +47,12 @@ discard block |
||
| 47 | 47 | $metadata = null, |
| 48 | 48 | $outputWanted) |
| 49 | 49 | { |
| 50 | - if (!$metadata) |
|
| 51 | - throw new CpeSdk\CpeException( |
|
| 50 | + if (!$metadata) { |
|
| 51 | + throw new CpeSdk\CpeException( |
|
| 52 | 52 | "NO Input Video metadata! We can't transcode an asset without probing it first. Use ValidateAsset activity to probe it and pass a 'metadata' field containing the input metadata to this TranscodeAsset activity.", |
| 53 | 53 | self::TRANSCODE_FAIL |
| 54 | 54 | ); |
| 55 | + } |
|
| 55 | 56 | |
| 56 | 57 | $ffmpegCmd = ""; |
| 57 | 58 | |
@@ -97,13 +98,14 @@ discard block |
||
| 97 | 98 | $this->activityLogKey |
| 98 | 99 | ); |
| 99 | 100 | |
| 100 | - if ($metadata) |
|
| 101 | - $this->cpeLogger->log_out( |
|
| 101 | + if ($metadata) { |
|
| 102 | + $this->cpeLogger->log_out( |
|
| 102 | 103 | "INFO", |
| 103 | 104 | basename(__FILE__), |
| 104 | 105 | "Input Video metadata: " . print_r($metadata, true), |
| 105 | 106 | $this->activityLogKey |
| 106 | 107 | ); |
| 108 | + } |
|
| 107 | 109 | |
| 108 | 110 | try { |
| 109 | 111 | // Use executer to start FFMpeg command |
@@ -133,8 +135,7 @@ discard block |
||
| 133 | 135 | // FFProbe the output file and return its information |
| 134 | 136 | $output_info = |
| 135 | 137 | $this->get_asset_info($pathToOutputFiles."/".$outputWanted->{'output_file_info'}['basename']); |
| 136 | - } |
|
| 137 | - catch (\Exception $e) { |
|
| 138 | + } catch (\Exception $e) { |
|
| 138 | 139 | $this->cpeLogger->log_out( |
| 139 | 140 | "ERROR", |
| 140 | 141 | basename(__FILE__), |
@@ -284,8 +285,7 @@ discard block |
||
| 284 | 285 | $time = gmdate("H:i:s", $snapshot_sec) . ".000"; |
| 285 | 286 | $pathToOutputFiles .= "/" . $outputFileInfo['basename']; |
| 286 | 287 | $frameOptions = " -ss $time -vframes 1"; |
| 287 | - } |
|
| 288 | - else if ($outputWanted->{'mode'} == 'intervals') |
|
| 288 | + } else if ($outputWanted->{'mode'} == 'intervals') |
|
| 289 | 289 | { |
| 290 | 290 | $intervals = self::INTERVALS_DEFAULT; |
| 291 | 291 | if (isset($outputWanted->{'intervals'}) && |
@@ -338,8 +338,7 @@ discard block |
||
| 338 | 338 | array(1 => array("pipe", "w"), 2 => array("pipe", "w")), |
| 339 | 339 | false, false, |
| 340 | 340 | false, 1); |
| 341 | - } |
|
| 342 | - catch (\Exception $e) { |
|
| 341 | + } catch (\Exception $e) { |
|
| 343 | 342 | $this->cpeLogger->log_out( |
| 344 | 343 | "ERROR", |
| 345 | 344 | basename(__FILE__), |
@@ -610,8 +609,7 @@ discard block |
||
| 610 | 609 | false, false, |
| 611 | 610 | false, 1 |
| 612 | 611 | ); |
| 613 | - } |
|
| 614 | - catch (\Exception $e) { |
|
| 612 | + } catch (\Exception $e) { |
|
| 615 | 613 | $this->cpeLogger->log_out( |
| 616 | 614 | "ERROR", |
| 617 | 615 | basename(__FILE__), |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | * We use ffprobe, ffmpeg and convert to analyse, transcode and manipulate videos and images (watermark) |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -require_once __DIR__ . '/BasicTranscoder.php'; |
|
| 10 | +require_once __DIR__.'/BasicTranscoder.php'; |
|
| 11 | 11 | |
| 12 | 12 | use SA\CpeSdk; |
| 13 | 13 | |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | $this->cpeLogger->log_out( |
| 104 | 104 | "INFO", |
| 105 | 105 | basename(__FILE__), |
| 106 | - "Input Video metadata: " . print_r($metadata, true), |
|
| 106 | + "Input Video metadata: ".print_r($metadata, true), |
|
| 107 | 107 | $this->activityLogKey |
| 108 | 108 | ); |
| 109 | 109 | |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | $this->cpeLogger->log_out( |
| 141 | 141 | "ERROR", |
| 142 | 142 | basename(__FILE__), |
| 143 | - "Execution of command '".$ffmpegCmd."' failed: " . print_r($metadata, true). ". ".$e->getMessage(), |
|
| 143 | + "Execution of command '".$ffmpegCmd."' failed: ".print_r($metadata, true).". ".$e->getMessage(), |
|
| 144 | 144 | $this->activityLogKey |
| 145 | 145 | ); |
| 146 | 146 | return false; |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | // Append output filename to path |
| 186 | - $pathToOutputFiles .= "/" . $outputWanted->{'output_file_info'}['basename']; |
|
| 186 | + $pathToOutputFiles .= "/".$outputWanted->{'output_file_info'}['basename']; |
|
| 187 | 187 | // Replace ${output_file} by output filename and path to local disk |
| 188 | 188 | $ffmpegCmd = preg_replace('/\$\{output_file\}/', $pathToOutputFiles, $ffmpegCmd); |
| 189 | 189 | |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | // Create FFMpeg arguments |
| 246 | - $ffmpegArgs = " -i $pathToInputFile -y -threads 0"; |
|
| 246 | + $ffmpegArgs = " -i $pathToInputFile -y -threads 0"; |
|
| 247 | 247 | $ffmpegArgs .= " -s $size"; |
| 248 | 248 | $ffmpegArgs .= " -vcodec $videoCodec"; |
| 249 | 249 | $ffmpegArgs .= " -acodec $audioCodec"; |
@@ -254,9 +254,9 @@ discard block |
||
| 254 | 254 | $ffmpegArgs .= " $watermarkOptions"; |
| 255 | 255 | |
| 256 | 256 | // Append output filename to path |
| 257 | - $pathToOutputFiles .= "/" . $outputWanted->{'output_file_info'}['basename']; |
|
| 257 | + $pathToOutputFiles .= "/".$outputWanted->{'output_file_info'}['basename']; |
|
| 258 | 258 | // Final command |
| 259 | - $ffmpegCmd = "ffmpeg $ffmpegArgs $pathToOutputFiles"; |
|
| 259 | + $ffmpegCmd = "ffmpeg $ffmpegArgs $pathToOutputFiles"; |
|
| 260 | 260 | |
| 261 | 261 | return ($ffmpegCmd); |
| 262 | 262 | } |
@@ -283,8 +283,8 @@ discard block |
||
| 283 | 283 | $snapshot_sec = $outputWanted->{'snapshot_sec'}; |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | - $time = gmdate("H:i:s", $snapshot_sec) . ".000"; |
|
| 287 | - $pathToOutputFiles .= "/" . $outputFileInfo['basename']; |
|
| 286 | + $time = gmdate("H:i:s", $snapshot_sec).".000"; |
|
| 287 | + $pathToOutputFiles .= "/".$outputFileInfo['basename']; |
|
| 288 | 288 | $frameOptions = " -ss $time -vframes 1"; |
| 289 | 289 | } |
| 290 | 290 | else if ($outputWanted->{'mode'} == 'intervals') |
@@ -295,14 +295,14 @@ discard block |
||
| 295 | 295 | $intervals = $outputWanted->{'intervals'}; |
| 296 | 296 | } |
| 297 | 297 | |
| 298 | - $pathToOutputFiles .= "/" . $outputFileInfo['filename'] . "%06d." |
|
| 298 | + $pathToOutputFiles .= "/".$outputFileInfo['filename']."%06d." |
|
| 299 | 299 | . $outputFileInfo['extension']; |
| 300 | 300 | $frameOptions = " -vf fps=fps=1/$intervals"; |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | // Create FFMpeg arguments |
| 304 | - $ffmpegArgs = " -i $pathToInputFile -y -threads 0"; |
|
| 305 | - $ffmpegArgs .= " -vf scale=" . $outputWanted->{'size'}; |
|
| 304 | + $ffmpegArgs = " -i $pathToInputFile -y -threads 0"; |
|
| 305 | + $ffmpegArgs .= " -vf scale=".$outputWanted->{'size'}; |
|
| 306 | 306 | $ffmpegArgs .= " $frameOptions -f image2 -q:v 8"; |
| 307 | 307 | |
| 308 | 308 | // Final command |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | $this->activityLogKey); |
| 334 | 334 | |
| 335 | 335 | // Transform watermark for opacity |
| 336 | - $convertCmd = "convert $watermarkPath -alpha on -channel A -evaluate Multiply " . $watermarkOptions->{'opacity'} . " +channel $newWatermarkPath"; |
|
| 336 | + $convertCmd = "convert $watermarkPath -alpha on -channel A -evaluate Multiply ".$watermarkOptions->{'opacity'}." +channel $newWatermarkPath"; |
|
| 337 | 337 | |
| 338 | 338 | try { |
| 339 | 339 | $out = $this->executer->execute($convertCmd, 1, |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | // Format options for FFMpeg |
| 363 | 363 | $size = $watermarkOptions->{'size'}; |
| 364 | 364 | $positions = $this->get_watermark_position($watermarkOptions); |
| 365 | - $formattedOptions = "-vf \"movie=$newWatermarkPath, scale=$size [wm]; [in][wm] overlay=" . $positions['x'] . ':' . $positions['y'] . " [out]\""; |
|
| 365 | + $formattedOptions = "-vf \"movie=$newWatermarkPath, scale=$size [wm]; [in][wm] overlay=".$positions['x'].':'.$positions['y']." [out]\""; |
|
| 366 | 366 | |
| 367 | 367 | return ($formattedOptions); |
| 368 | 368 | } |
@@ -379,10 +379,10 @@ discard block |
||
| 379 | 379 | $positions['y'] = $watermarkOptions->{'y'}; |
| 380 | 380 | } |
| 381 | 381 | if ($watermarkOptions->{'x'} < 0) { |
| 382 | - $positions['x'] = 'main_w-overlay_w' . $watermarkOptions->{'x'}; |
|
| 382 | + $positions['x'] = 'main_w-overlay_w'.$watermarkOptions->{'x'}; |
|
| 383 | 383 | } |
| 384 | 384 | if ($watermarkOptions->{'y'} < 0) { |
| 385 | - $positions['y'] = 'main_h-overlay_h' . $watermarkOptions->{'y'}; |
|
| 385 | + $positions['y'] = 'main_h-overlay_h'.$watermarkOptions->{'y'}; |
|
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | return ($positions); |
@@ -441,7 +441,7 @@ discard block |
||
| 441 | 441 | if (!isset($outputWanted->{'allow_upscale'}) || |
| 442 | 442 | $outputWanted->{'allow_upscale'} == 'false') |
| 443 | 443 | { |
| 444 | - $metadata->{'size'} = $metadata->width . 'x' . $metadata->height; |
|
| 444 | + $metadata->{'size'} = $metadata->width.'x'.$metadata->height; |
|
| 445 | 445 | $inputSize = $metadata->{'size'}; |
| 446 | 446 | $inputSizeSplit = explode("x", $inputSize); |
| 447 | 447 | $outputSizeSplit = explode("x", $size); |
@@ -493,7 +493,7 @@ discard block |
||
| 493 | 493 | // # finally, progress is easy |
| 494 | 494 | $progress = 0; |
| 495 | 495 | if ($done) { |
| 496 | - $progress = round(($done/$duration)*100); |
|
| 496 | + $progress = round(($done / $duration) * 100); |
|
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | $this->cpeLogger->log_out( |
@@ -528,7 +528,7 @@ discard block |
||
| 528 | 528 | } |
| 529 | 529 | |
| 530 | 530 | $preset = $output_wanted->{"preset"}; |
| 531 | - $presetPath = __DIR__ . '/../../../presets/'; |
|
| 531 | + $presetPath = __DIR__.'/../../../presets/'; |
|
| 532 | 532 | |
| 533 | 533 | if (!($presetContent = file_get_contents($presetPath.$preset.".json"))) { |
| 534 | 534 | throw new CpeSdk\CpeException("Can't open preset file !", |
@@ -552,7 +552,7 @@ discard block |
||
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | $preset = $output->{"preset"}; |
| 555 | - $presetPath = __DIR__ . '/../../../presets/'; |
|
| 555 | + $presetPath = __DIR__.'/../../../presets/'; |
|
| 556 | 556 | |
| 557 | 557 | if (!($files = scandir($presetPath))) { |
| 558 | 558 | throw new CpeSdk\CpeException("Unable to open preset directory '$presetPath' !", |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | isset($this->input->{'input_asset'}->{'file'})) |
| 103 | 103 | { |
| 104 | 104 | // Make pre-signed URL so ffmpeg has access to file |
| 105 | - $this->pathToInputFile = 'cache:' . |
|
| 105 | + $this->pathToInputFile = 'cache:'. |
|
| 106 | 106 | $this->s3->getCommand('GetObject', [ |
| 107 | 107 | 'Bucket' => $this->input->{'input_asset'}->{'bucket'}, |
| 108 | 108 | 'Key' => $this->input->{'input_asset'}->{'file'} |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | else if ($this->input->{'input_asset'}->{'http'}) |
| 112 | 112 | { |
| 113 | 113 | // Pad HTTP input so it is cached in case of full encodes |
| 114 | - $this->pathToInputFile = 'cache:' . $this->input->{'input_asset'}->{'http'}; |
|
| 114 | + $this->pathToInputFile = 'cache:'.$this->input->{'input_asset'}->{'http'}; |
|
| 115 | 115 | } |
| 116 | 116 | } |
| 117 | 117 | |
@@ -79,22 +79,25 @@ discard block |
||
| 79 | 79 | |
| 80 | 80 | $inputFileInfo = null; |
| 81 | 81 | // Create TMP storage to store input file to transcode |
| 82 | - if (isset($this->input->{'input_asset'}->{'file'})) |
|
| 83 | - $inputFileInfo = pathinfo($this->input->{'input_asset'}->{'file'}); |
|
| 82 | + if (isset($this->input->{'input_asset'}->{'file'})) { |
|
| 83 | + $inputFileInfo = pathinfo($this->input->{'input_asset'}->{'file'}); |
|
| 84 | + } |
|
| 84 | 85 | |
| 85 | 86 | // Create the tmp folder if doesn't exist |
| 86 | 87 | if (!file_exists($this->tmpPathInput)) |
| 87 | 88 | { |
| 88 | - if ($this->debug) |
|
| 89 | - $this->cpeLogger->log_out("INFO", basename(__FILE__), |
|
| 89 | + if ($this->debug) { |
|
| 90 | + $this->cpeLogger->log_out("INFO", basename(__FILE__), |
|
| 90 | 91 | "Creating TMP input folder '".$this->tmpPathInput."'", |
| 91 | 92 | $this->activityLogKey); |
| 93 | + } |
|
| 92 | 94 | |
| 93 | - if (!mkdir($this->tmpPathInput, 0750, true)) |
|
| 94 | - throw new CpeSdk\CpeException( |
|
| 95 | + if (!mkdir($this->tmpPathInput, 0750, true)) { |
|
| 96 | + throw new CpeSdk\CpeException( |
|
| 95 | 97 | "Unable to create temporary folder '$this->tmpPathInput' !", |
| 96 | 98 | self::TMP_FOLDER_FAIL |
| 97 | 99 | ); |
| 100 | + } |
|
| 98 | 101 | } |
| 99 | 102 | |
| 100 | 103 | $this->pathToInputFile = null; |
@@ -107,8 +110,7 @@ discard block |
||
| 107 | 110 | 'Bucket' => $this->input->{'input_asset'}->{'bucket'}, |
| 108 | 111 | 'Key' => $this->input->{'input_asset'}->{'file'} |
| 109 | 112 | ])->createPresignedUrl('+1 day'); |
| 110 | - } |
|
| 111 | - else if ($this->input->{'input_asset'}->{'http'}) |
|
| 113 | + } else if ($this->input->{'input_asset'}->{'http'}) |
|
| 112 | 114 | { |
| 113 | 115 | // Pad HTTP input so it is cached in case of full encodes |
| 114 | 116 | $this->pathToInputFile = 'cache:' . $this->input->{'input_asset'}->{'http'}; |
@@ -167,16 +167,18 @@ |
||
| 167 | 167 | |
| 168 | 168 | if (!file_exists($this->pathToOutputFiles)) |
| 169 | 169 | { |
| 170 | - if ($this->debug) |
|
| 171 | - $this->cpeLogger->log_out("INFO", basename(__FILE__), |
|
| 170 | + if ($this->debug) { |
|
| 171 | + $this->cpeLogger->log_out("INFO", basename(__FILE__), |
|
| 172 | 172 | "Creating TMP output folder '".$this->pathToOutputFiles."'", |
| 173 | 173 | $this->activityLogKey); |
| 174 | + } |
|
| 174 | 175 | |
| 175 | - if (!mkdir($this->pathToOutputFiles, 0750, true)) |
|
| 176 | - throw new CpeSdk\CpeException( |
|
| 176 | + if (!mkdir($this->pathToOutputFiles, 0750, true)) { |
|
| 177 | + throw new CpeSdk\CpeException( |
|
| 177 | 178 | "Unable to create temporary folder '$this->pathToOutputFiles' !", |
| 178 | 179 | self::TMP_FOLDER_FAIL |
| 179 | 180 | ); |
| 181 | + } |
|
| 180 | 182 | } |
| 181 | 183 | } |
| 182 | 184 | |
@@ -48,7 +48,7 @@ |
||
| 48 | 48 | $tmpFile = tempname(sys_get_temp_dir(), 'ct'); |
| 49 | 49 | file_put_contents($tmpFile, $obj['Body']); |
| 50 | 50 | $mime = trim((new CommandExecuter($this->cpeLogger))->execute( |
| 51 | - 'file -b --mime-type ' . escapeshellarg($tmpFile))['out']); |
|
| 51 | + 'file -b --mime-type '.escapeshellarg($tmpFile))['out']); |
|
| 52 | 52 | $type = substr($mime, 0, strpos($mime, '/')); |
| 53 | 53 | |
| 54 | 54 | $this->cpeLogger->log_out( |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -require_once __DIR__ . '/BasicTranscoder.php'; |
|
| 3 | +require_once __DIR__.'/BasicTranscoder.php'; |
|
| 4 | 4 | |
| 5 | 5 | class AudioTranscoder extends BasicTranscoder |
| 6 | 6 | { |
@@ -45,7 +45,9 @@ |
||
| 45 | 45 | |
| 46 | 46 | public function is_dir_empty($dir) |
| 47 | 47 | { |
| 48 | - if (!is_readable($dir)) return null; |
|
| 48 | + if (!is_readable($dir)) { |
|
| 49 | + return null; |
|
| 50 | + } |
|
| 49 | 51 | $handle = opendir($dir); |
| 50 | 52 | while (false !== ($entry = readdir($handle))) { |
| 51 | 53 | if ($entry !== '.' && $entry !== '..') { |
@@ -4,13 +4,13 @@ discard block |
||
| 4 | 4 | * Script used to get a file in AWS S3 |
| 5 | 5 | **/ |
| 6 | 6 | |
| 7 | -require __DIR__ . "/../../vendor/autoload.php"; |
|
| 7 | +require __DIR__."/../../vendor/autoload.php"; |
|
| 8 | 8 | |
| 9 | 9 | use Aws\S3\S3Client; |
| 10 | 10 | |
| 11 | 11 | function usage() |
| 12 | 12 | { |
| 13 | - echo("Usage: php ". basename(__FILE__) . " [-h] [--force] --bucket <s3 bucket> --file <filename> --to <filepath>\n"); |
|
| 13 | + echo("Usage: php ".basename(__FILE__)." [-h] [--force] --bucket <s3 bucket> --file <filename> --to <filepath>\n"); |
|
| 14 | 14 | echo("--help, -h: Print this help\n"); |
| 15 | 15 | echo("--bucket <s3 bucket>: Name of the S3 bucket\n"); |
| 16 | 16 | echo("--file <filename>: Name of the file in the S3 bucket\n"); |
@@ -41,8 +41,8 @@ discard block |
||
| 41 | 41 | file_exists($options['to']) && |
| 42 | 42 | filesize($options['to'])) |
| 43 | 43 | { |
| 44 | - print json_encode([ "status" => "SUCCESS", |
|
| 45 | - "msg" => "[".__FILE__."] Using local copy: '" . $options['to'] . "'" ]); |
|
| 44 | + print json_encode(["status" => "SUCCESS", |
|
| 45 | + "msg" => "[".__FILE__."] Using local copy: '".$options['to']."'"]); |
|
| 46 | 46 | exit(0); |
| 47 | 47 | } |
| 48 | 48 | |
@@ -58,14 +58,14 @@ discard block |
||
| 58 | 58 | )); |
| 59 | 59 | |
| 60 | 60 | // Print JSON error output |
| 61 | - print json_encode([ "status" => "SUCCESS", |
|
| 62 | - "msg" => "[".__FILE__."] Download '" . $options['bucket'] . "/" . $options['file'] . "' successful !" ]); |
|
| 61 | + print json_encode(["status" => "SUCCESS", |
|
| 62 | + "msg" => "[".__FILE__."] Download '".$options['bucket']."/".$options['file']."' successful !"]); |
|
| 63 | 63 | } |
| 64 | 64 | catch (Exception $e) { |
| 65 | - $err = "Unable to get '" . $options['bucket'] . "/" . $options['file'] . "' file from S3 ! " . $e->getMessage(); |
|
| 65 | + $err = "Unable to get '".$options['bucket']."/".$options['file']."' file from S3 ! ".$e->getMessage(); |
|
| 66 | 66 | // Print JSON error output |
| 67 | - print json_encode([ "status" => "ERROR", |
|
| 68 | - "msg" => "[".__FILE__."] $err" ]); |
|
| 67 | + print json_encode(["status" => "ERROR", |
|
| 68 | + "msg" => "[".__FILE__."] $err"]); |
|
| 69 | 69 | |
| 70 | 70 | die("[".__FILE__."] $err"); |
| 71 | 71 | } |
@@ -22,8 +22,9 @@ discard block |
||
| 22 | 22 | function check_input_parameters($options) |
| 23 | 23 | { |
| 24 | 24 | if (!count($options) || isset($options['h']) || |
| 25 | - isset($options['help'])) |
|
| 26 | - usage(); |
|
| 25 | + isset($options['help'])) { |
|
| 26 | + usage(); |
|
| 27 | + } |
|
| 27 | 28 | |
| 28 | 29 | if (!isset($options['bucket']) || !isset($options['file']) || |
| 29 | 30 | !isset($options['to'])) |
@@ -60,8 +61,7 @@ discard block |
||
| 60 | 61 | // Print JSON error output |
| 61 | 62 | print json_encode([ "status" => "SUCCESS", |
| 62 | 63 | "msg" => "[".__FILE__."] Download '" . $options['bucket'] . "/" . $options['file'] . "' successful !" ]); |
| 63 | -} |
|
| 64 | -catch (Exception $e) { |
|
| 64 | +} catch (Exception $e) { |
|
| 65 | 65 | $err = "Unable to get '" . $options['bucket'] . "/" . $options['file'] . "' file from S3 ! " . $e->getMessage(); |
| 66 | 66 | // Print JSON error output |
| 67 | 67 | print json_encode([ "status" => "ERROR", |
@@ -4,13 +4,13 @@ discard block |
||
| 4 | 4 | * Script used to put a file in AWS S3 |
| 5 | 5 | **/ |
| 6 | 6 | |
| 7 | -require __DIR__ . "/../../vendor/autoload.php"; |
|
| 7 | +require __DIR__."/../../vendor/autoload.php"; |
|
| 8 | 8 | |
| 9 | 9 | use Aws\S3\S3Client; |
| 10 | 10 | |
| 11 | 11 | function usage() |
| 12 | 12 | { |
| 13 | - echo("Usage: php ". basename(__FILE__) . " [-h] [--rrs::] [--encrypt::] --bucket <s3 bucket> --file <filename> --from <filepath>\n"); |
|
| 13 | + echo("Usage: php ".basename(__FILE__)." [-h] [--rrs::] [--encrypt::] --bucket <s3 bucket> --file <filename> --from <filepath>\n"); |
|
| 14 | 14 | echo("--help, -h: Print this help\n"); |
| 15 | 15 | echo("--bucket <s3 bucket>: Name of the S3 bucket\n"); |
| 16 | 16 | echo("--file <filename>: Name of the file to create in bucket. You can override local filename.\n"); |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | usage(); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - $options['bucket'] = rtrim( $options['bucket'], "/"); |
|
| 36 | + $options['bucket'] = rtrim($options['bucket'], "/"); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | $options = getopt("h", [ |
@@ -66,15 +66,15 @@ discard block |
||
| 66 | 66 | $s3->putObject($params); |
| 67 | 67 | |
| 68 | 68 | // Print JSON error output |
| 69 | - print json_encode([ "status" => "SUCCESS", |
|
| 70 | - "msg" => "[".__FILE__."] Upload '" . $options['from'] . "' to '" . $options['bucket'] . "/" . $options['file'] . "' successful !" ]); |
|
| 69 | + print json_encode(["status" => "SUCCESS", |
|
| 70 | + "msg" => "[".__FILE__."] Upload '".$options['from']."' to '".$options['bucket']."/".$options['file']."' successful !"]); |
|
| 71 | 71 | } |
| 72 | 72 | catch (Exception $e) { |
| 73 | - $err = "Unable to put file '" . $options['from'] . "' into S3: '" . $options['bucket'] . "/" . $options['file'] . "'! " . $e->getMessage(); |
|
| 73 | + $err = "Unable to put file '".$options['from']."' into S3: '".$options['bucket']."/".$options['file']."'! ".$e->getMessage(); |
|
| 74 | 74 | |
| 75 | 75 | // Print JSON error output |
| 76 | - print json_encode([ "status" => "ERROR", |
|
| 77 | - "msg" => "[".__FILE__."] $err" ]); |
|
| 76 | + print json_encode(["status" => "ERROR", |
|
| 77 | + "msg" => "[".__FILE__."] $err"]); |
|
| 78 | 78 | |
| 79 | 79 | die("[".__FILE__."] $err"); |
| 80 | 80 | } |
@@ -23,8 +23,9 @@ discard block |
||
| 23 | 23 | function check_input_parameters(&$options) |
| 24 | 24 | { |
| 25 | 25 | if (!count($options) || isset($options['h']) || |
| 26 | - isset($options['help'])) |
|
| 27 | - usage(); |
|
| 26 | + isset($options['help'])) { |
|
| 27 | + usage(); |
|
| 28 | + } |
|
| 28 | 29 | |
| 29 | 30 | if (!isset($options['bucket']) || !isset($options['file']) || |
| 30 | 31 | !isset($options['from'])) |
@@ -57,10 +58,12 @@ discard block |
||
| 57 | 58 | ); |
| 58 | 59 | |
| 59 | 60 | // StorageClass and Encryption ? |
| 60 | - if (isset($options['rrs'])) |
|
| 61 | - $params['StorageClass'] = 'REDUCED_REDUNDANCY'; |
|
| 62 | - if (isset($options['encrypt'])) |
|
| 63 | - $params['ServerSideEncryption'] = 'AES256'; |
|
| 61 | + if (isset($options['rrs'])) { |
|
| 62 | + $params['StorageClass'] = 'REDUCED_REDUNDANCY'; |
|
| 63 | + } |
|
| 64 | + if (isset($options['encrypt'])) { |
|
| 65 | + $params['ServerSideEncryption'] = 'AES256'; |
|
| 66 | + } |
|
| 64 | 67 | |
| 65 | 68 | // Upload and Save file to S3 |
| 66 | 69 | $s3->putObject($params); |
@@ -68,8 +71,7 @@ discard block |
||
| 68 | 71 | // Print JSON error output |
| 69 | 72 | print json_encode([ "status" => "SUCCESS", |
| 70 | 73 | "msg" => "[".__FILE__."] Upload '" . $options['from'] . "' to '" . $options['bucket'] . "/" . $options['file'] . "' successful !" ]); |
| 71 | -} |
|
| 72 | -catch (Exception $e) { |
|
| 74 | +} catch (Exception $e) { |
|
| 73 | 75 | $err = "Unable to put file '" . $options['from'] . "' into S3: '" . $options['bucket'] . "/" . $options['file'] . "'! " . $e->getMessage(); |
| 74 | 76 | |
| 75 | 77 | // Print JSON error output |
@@ -17,8 +17,9 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | public function __construct($cpeLogger = null) |
| 19 | 19 | { |
| 20 | - if (!$cpeLogger) |
|
| 21 | - $this->cpeLogger = new CpeSdk\CpeLogger(null, 'CommandExecuter'); |
|
| 20 | + if (!$cpeLogger) { |
|
| 21 | + $this->cpeLogger = new CpeSdk\CpeLogger(null, 'CommandExecuter'); |
|
| 22 | + } |
|
| 22 | 23 | $this->cpeLogger = $cpeLogger; |
| 23 | 24 | } |
| 24 | 25 | |
@@ -112,10 +113,12 @@ discard block |
||
| 112 | 113 | if ($procStatus['exitcode'] > 0) |
| 113 | 114 | { |
| 114 | 115 | $this->cpeLogger->log_out("ERROR", basename(__FILE__), "Can't execute: $cmd. Exit Code: ".$procStatus['exitcode']); |
| 115 | - if ($allOut) |
|
| 116 | - $this->cpeLogger->log_out("ERROR", basename(__FILE__), "COMMAND STDOUT: ".$allOut); |
|
| 117 | - if ($allOutErr) |
|
| 118 | - $this->cpeLogger->log_out("ERROR", basename(__FILE__), "COMMAND STDERR: ".$allOutErr); |
|
| 116 | + if ($allOut) { |
|
| 117 | + $this->cpeLogger->log_out("ERROR", basename(__FILE__), "COMMAND STDOUT: ".$allOut); |
|
| 118 | + } |
|
| 119 | + if ($allOutErr) { |
|
| 120 | + $this->cpeLogger->log_out("ERROR", basename(__FILE__), "COMMAND STDERR: ".$allOutErr); |
|
| 121 | + } |
|
| 119 | 122 | } |
| 120 | 123 | |
| 121 | 124 | if ($showProgress) { |