Completed
Pull Request — master (#51)
by Tyler
02:38
created
src/activities/BasicActivity.php 1 patch
Braces   +10 added lines, -8 removed lines patch added patch discarded remove patch
@@ -79,22 +79,25 @@  discard block
 block discarded – undo
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
 block discarded – undo
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'};
Please login to merge, or discard this patch.
src/activities/TranscodeAssetActivity.php 1 patch
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -167,16 +167,18 @@
 block discarded – undo
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
     
Please login to merge, or discard this patch.
src/activities/transcoders/BasicTranscoder.php 1 patch
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -45,7 +45,9 @@
 block discarded – undo
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 !== '..') { 
Please login to merge, or discard this patch.
src/scripts/getFromS3.php 1 patch
Braces   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -22,8 +22,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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",
Please login to merge, or discard this patch.
src/scripts/putInS3.php 1 patch
Braces   +10 added lines, -8 removed lines patch added patch discarded remove patch
@@ -23,8 +23,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
Please login to merge, or discard this patch.
src/utils/CommandExecuter.php 1 patch
Braces   +9 added lines, -6 removed lines patch added patch discarded remove patch
@@ -17,8 +17,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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) {
Please login to merge, or discard this patch.
src/utils/S3Utils.php 1 patch
Braces   +21 added lines, -14 removed lines patch added patch discarded remove patch
@@ -22,8 +22,9 @@  discard block
 block discarded – undo
22 22
     
23 23
     public function __construct($cpeLogger = null)
24 24
     {
25
-        if (!$cpeLogger)
26
-            $this->cpeLogger = new CpeSdk\CpeLogger(null, 'S3Utils');
25
+        if (!$cpeLogger) {
26
+                    $this->cpeLogger = new CpeSdk\CpeLogger(null, 'S3Utils');
27
+        }
27 28
         $this->cpeLogger = $cpeLogger;
28 29
     }
29 30
 
@@ -61,10 +62,12 @@  discard block
 block discarded – undo
61 62
         $cmd .= " --bucket $bucket";
62 63
         $cmd .= " --file $filename";
63 64
         $cmd .= " --from $pathToFileToSend";
64
-        if ($options['rrs'])
65
-            $cmd .= " --rrs";
66
-        if ($options['encrypt'])
67
-            $cmd .= " --encrypt";
65
+        if ($options['rrs']) {
66
+                    $cmd .= " --rrs";
67
+        }
68
+        if ($options['encrypt']) {
69
+                    $cmd .= " --encrypt";
70
+        }
68 71
     
69 72
         // HAndle execution
70 73
         return ($this->handle_s3_ops(
@@ -91,21 +94,25 @@  discard block
 block discarded – undo
91 94
             true,
92 95
             5);
93 96
         
94
-        if ($out['outErr'])
95
-            throw new CpeSdk\CpeException($out['outErr'],
97
+        if ($out['outErr']) {
98
+                    throw new CpeSdk\CpeException($out['outErr'],
96 99
                 self::S3_OPS_FAILED);
100
+        }
97 101
 
98
-        if (!$out['out'])
99
-            throw new CpeSdk\CpeException("Script '$caller' didn't return any data !",
102
+        if (!$out['out']) {
103
+                    throw new CpeSdk\CpeException("Script '$caller' didn't return any data !",
100 104
                 self::NO_OUTPUT_DATA);
105
+        }
101 106
     
102
-        if (!($decoded = json_decode($out['out'], true)))
103
-            throw new CpeSdk\CpeException($out['out'],
107
+        if (!($decoded = json_decode($out['out'], true))) {
108
+                    throw new CpeSdk\CpeException($out['out'],
104 109
                 self::S3_OPS_FAILED);
110
+        }
105 111
     
106
-        if ($decoded["status"] == "ERROR")
107
-            throw new CpeSdk\CpeException($decoded["msg"],
112
+        if ($decoded["status"] == "ERROR") {
113
+                    throw new CpeSdk\CpeException($decoded["msg"],
108 114
                 self::S3_OPS_FAILED);
115
+        }
109 116
 
110 117
         return ($decoded);
111 118
     }
Please login to merge, or discard this patch.
src/activities/transcoders/VideoTranscoder.php 1 patch
Braces   +11 added lines, -14 removed lines patch added patch discarded remove patch
@@ -49,11 +49,12 @@  discard block
 block discarded – undo
49 49
         $metadata = null, 
50 50
         $outputWanted)
51 51
     {
52
-        if (!$metadata)
53
-            throw new CpeSdk\CpeException(
52
+        if (!$metadata) {
53
+                    throw new CpeSdk\CpeException(
54 54
                 "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.",
55 55
                 self::TRANSCODE_FAIL
56 56
             );
57
+        }
57 58
         // Extract an sanitize metadata
58 59
         $metadata = $this->_extractFileInfo($metadata);
59 60
 
@@ -101,13 +102,14 @@  discard block
 block discarded – undo
101 102
             $this->activityLogKey
102 103
         );
103 104
         
104
-        if ($metadata)
105
-            $this->cpeLogger->log_out(
105
+        if ($metadata) {
106
+                    $this->cpeLogger->log_out(
106 107
                 "INFO", 
107 108
                 basename(__FILE__), 
108 109
                 "Input Video metadata: " . print_r($metadata, true),
109 110
                 $this->activityLogKey
110 111
             );
112
+        }
111 113
         
112 114
         try {
113 115
             // Use executer to start FFMpeg command
@@ -137,8 +139,7 @@  discard block
 block discarded – undo
137 139
             // FFProbe the output file and return its information
138 140
             $output_info =
139 141
                 $this->get_asset_info($pathToOutputFiles."/".$outputWanted->{'output_file_info'}['basename']);
140
-        }
141
-        catch (\Exception $e) {
142
+        } catch (\Exception $e) {
142 143
             $this->cpeLogger->log_out(
143 144
                 "ERROR", 
144 145
                 basename(__FILE__), 
@@ -288,8 +289,7 @@  discard block
 block discarded – undo
288 289
             $time = gmdate("H:i:s", $snapshot_sec) . ".000";
289 290
             $pathToOutputFiles .= "/" . $outputFileInfo['basename'];
290 291
             $frameOptions = " -ss $time -vframes 1";
291
-        }
292
-        else if ($outputWanted->{'mode'} == 'intervals')
292
+        } else if ($outputWanted->{'mode'} == 'intervals')
293 293
         {
294 294
             $intervals = self::INTERVALS_DEFAULT;
295 295
             if (isset($outputWanted->{'intervals'}) &&
@@ -342,8 +342,7 @@  discard block
 block discarded – undo
342 342
                 array(1 => array("pipe", "w"), 2 => array("pipe", "w")),
343 343
                 false, false, 
344 344
                 false, 1);
345
-        }
346
-        catch (\Exception $e) {
345
+        } catch (\Exception $e) {
347 346
             $this->cpeLogger->log_out(
348 347
                 "ERROR", 
349 348
                 basename(__FILE__), 
@@ -601,8 +600,7 @@  discard block
 block discarded – undo
601 600
         foreach ($metadata->streams as $key => $value) {
602 601
             if ($value->codec_type === 'video') {
603 602
                 $videoStreams = $value;
604
-            }
605
-            else if ($value->codec_type === 'audio') {
603
+            } else if ($value->codec_type === 'audio') {
606 604
                 $audioStreams = $value;
607 605
             }
608 606
         }
@@ -653,8 +651,7 @@  discard block
 block discarded – undo
653 651
                 false, false, 
654 652
                 false, 1
655 653
             );
656
-        }
657
-        catch (\Exception $e) {
654
+        } catch (\Exception $e) {
658 655
             $this->cpeLogger->log_out(
659 656
                 "ERROR", 
660 657
                 basename(__FILE__), 
Please login to merge, or discard this patch.