@@ -11,7 +11,7 @@ |
||
11 | 11 | |
12 | 12 | namespace Projectmentor\Quota\Helpers; |
13 | 13 | |
14 | -use Illuminate\Filesystem\Filesystem; |
|
14 | +use Illuminate\Filesystem\Filesystem; |
|
15 | 15 | use Illuminate\Filesystem\ClassFinder; |
16 | 16 | |
17 | 17 | /** |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @return void |
39 | 39 | */ |
40 | - public function migrate($path=null, $files=[]) |
|
40 | + public function migrate($path = null, $files = []) |
|
41 | 41 | { |
42 | 42 | //default migration path; |
43 | 43 | $this->migrations_path = base_path('database/migrations'); |
@@ -46,23 +46,23 @@ discard block |
||
46 | 46 | $fileSystem = app(Filesystem::class); |
47 | 47 | $classFinder = app(ClassFinder::class); |
48 | 48 | |
49 | - if(!empty($files)){ |
|
49 | + if (!empty($files)) { |
|
50 | 50 | //run specific files |
51 | 51 | |
52 | - foreach($files as $file) |
|
52 | + foreach ($files as $file) |
|
53 | 53 | { |
54 | - $file = $this->migrations_path . "/" . $file; |
|
54 | + $file = $this->migrations_path."/".$file; |
|
55 | 55 | |
56 | 56 | $fileSystem->requireOnce($file); |
57 | 57 | $migrationClass = $classFinder->findClass($file); |
58 | 58 | (new $migrationClass)->up(); |
59 | 59 | } |
60 | 60 | |
61 | - }else{ |
|
61 | + } else { |
|
62 | 62 | |
63 | 63 | \Log::info($fileSystem->files($this->migrations_path)); |
64 | 64 | |
65 | - foreach($fileSystem->files($this->migrations_path) as $file) |
|
65 | + foreach ($fileSystem->files($this->migrations_path) as $file) |
|
66 | 66 | { |
67 | 67 | $fileSystem->requireOnce($file); |
68 | 68 | // var_dump($file); |
@@ -58,7 +58,7 @@ |
||
58 | 58 | (new $migrationClass)->up(); |
59 | 59 | } |
60 | 60 | |
61 | - }else{ |
|
61 | + } else{ |
|
62 | 62 | |
63 | 63 | \Log::info($fileSystem->files($this->migrations_path)); |
64 | 64 |
@@ -91,7 +91,6 @@ |
||
91 | 91 | * |
92 | 92 | * TODO: make static? |
93 | 93 | * |
94 | - * @param PeriodicQuota $quota |
|
95 | 94 | * @return string |
96 | 95 | */ |
97 | 96 | public function dateInTimezone() |
@@ -159,17 +159,17 @@ discard block |
||
159 | 159 | |
160 | 160 | if($this->limit < ($hits + 1)) |
161 | 161 | { |
162 | - $this->miss($stats->misses); |
|
163 | - throw new \ErrorException( |
|
164 | - __CLASS__ . '::' . __FUNCTION__ . |
|
165 | - ' Overquota. Exceeded daily limit: ' . $this->limit); |
|
162 | + $this->miss($stats->misses); |
|
163 | + throw new \ErrorException( |
|
164 | + __CLASS__ . '::' . __FUNCTION__ . |
|
165 | + ' Overquota. Exceeded daily limit: ' . $this->limit); |
|
166 | 166 | } |
167 | 167 | else |
168 | 168 | { |
169 | 169 | $this->hit($stats->hits); |
170 | 170 | $result = true; |
171 | 171 | } |
172 | - return isset($result); |
|
172 | + return isset($result); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
@@ -186,9 +186,9 @@ discard block |
||
186 | 186 | public function getStats($date) |
187 | 187 | { |
188 | 188 | return DB::table('quotalog') |
189 | - ->where('date', $date) |
|
190 | - ->where('connection', $this->connection) |
|
191 | - ->first(); |
|
189 | + ->where('date', $date) |
|
190 | + ->where('connection', $this->connection) |
|
191 | + ->first(); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -55,26 +55,26 @@ discard block |
||
55 | 55 | parent::__construct($connection); |
56 | 56 | |
57 | 57 | $this->connection = $connection; |
58 | - $this->index = 'quota.connections.' . $connection; |
|
58 | + $this->index = 'quota.connections.'.$connection; |
|
59 | 59 | |
60 | - $this->timezone = config($this->index . '.timezone'); |
|
61 | - if(is_null($this->timezone)) |
|
60 | + $this->timezone = config($this->index.'.timezone'); |
|
61 | + if (is_null($this->timezone)) |
|
62 | 62 | $this->timezone = config('quota.default_timezone'); |
63 | 63 | |
64 | - $this->log_table = config($this->index . '.log_table'); |
|
64 | + $this->log_table = config($this->index.'.log_table'); |
|
65 | 65 | |
66 | 66 | //Bootstrap log if record does not exist. |
67 | 67 | $dtz = new \DateTimeZone($this->timezone); |
68 | 68 | $now = new \DateTime(date("Y-m-d"), $dtz); |
69 | 69 | $date = $now->format("Y-m-d"); |
70 | 70 | $log_records = DB::select( |
71 | - 'SELECT * FROM' . |
|
72 | - ' ' . $this->log_table . |
|
73 | - ' WHERE date = ' . '\'' . $date . '\'' . |
|
74 | - ' AND connection = ' . '\'' . $connection . '\'' |
|
71 | + 'SELECT * FROM'. |
|
72 | + ' '.$this->log_table. |
|
73 | + ' WHERE date = '.'\''.$date.'\''. |
|
74 | + ' AND connection = '.'\''.$connection.'\'' |
|
75 | 75 | ); |
76 | 76 | |
77 | - if(empty($log_records)) |
|
77 | + if (empty($log_records)) |
|
78 | 78 | \Artisan::call('quota:reset', [ |
79 | 79 | 'date' => $date, |
80 | 80 | 'connection' => $connection |
@@ -114,11 +114,11 @@ discard block |
||
114 | 114 | $hits = $hits + 1; |
115 | 115 | |
116 | 116 | DB::statement( |
117 | - 'UPDATE ' . $this->log_table . |
|
118 | - ' SET hits = ' . $hits . |
|
119 | - ', updated_at = ' . '\'' . Carbon::now()->toDateTimeString() . '\'' . |
|
120 | - ' WHERE date = ' . '\'' . $date . '\'' . |
|
121 | - ' AND connection = ' . '\'' . $this->connection . '\'' |
|
117 | + 'UPDATE '.$this->log_table. |
|
118 | + ' SET hits = '.$hits. |
|
119 | + ', updated_at = '.'\''.Carbon::now()->toDateTimeString().'\''. |
|
120 | + ' WHERE date = '.'\''.$date.'\''. |
|
121 | + ' AND connection = '.'\''.$this->connection.'\'' |
|
122 | 122 | ); |
123 | 123 | } |
124 | 124 | |
@@ -134,11 +134,11 @@ discard block |
||
134 | 134 | $misses = $misses + 1; |
135 | 135 | |
136 | 136 | DB::statement( |
137 | - 'UPDATE ' . $this->log_table . |
|
138 | - ' SET misses = ' . $misses . |
|
139 | - ', updated_at = ' . '\'' . Carbon::now()->toDateTimeString() . '\'' . |
|
140 | - ' WHERE date = ' . '\'' . $date . '\'' . |
|
141 | - ' AND connection = ' . '\'' . $this->connection . '\'' |
|
137 | + 'UPDATE '.$this->log_table. |
|
138 | + ' SET misses = '.$misses. |
|
139 | + ', updated_at = '.'\''.Carbon::now()->toDateTimeString().'\''. |
|
140 | + ' WHERE date = '.'\''.$date.'\''. |
|
141 | + ' AND connection = '.'\''.$this->connection.'\'' |
|
142 | 142 | ); |
143 | 143 | } |
144 | 144 | |
@@ -157,12 +157,12 @@ discard block |
||
157 | 157 | $stats = $this->getStats($date); |
158 | 158 | $hits = (integer) $stats->hits; |
159 | 159 | |
160 | - if($this->limit < ($hits + 1)) |
|
160 | + if ($this->limit < ($hits + 1)) |
|
161 | 161 | { |
162 | 162 | $this->miss($stats->misses); |
163 | 163 | throw new \ErrorException( |
164 | - __CLASS__ . '::' . __FUNCTION__ . |
|
165 | - ' Overquota. Exceeded daily limit: ' . $this->limit); |
|
164 | + __CLASS__.'::'.__FUNCTION__. |
|
165 | + ' Overquota. Exceeded daily limit: '.$this->limit); |
|
166 | 166 | } |
167 | 167 | else |
168 | 168 | { |
@@ -58,8 +58,9 @@ discard block |
||
58 | 58 | $this->index = 'quota.connections.' . $connection; |
59 | 59 | |
60 | 60 | $this->timezone = config($this->index . '.timezone'); |
61 | - if(is_null($this->timezone)) |
|
62 | - $this->timezone = config('quota.default_timezone'); |
|
61 | + if(is_null($this->timezone)) { |
|
62 | + $this->timezone = config('quota.default_timezone'); |
|
63 | + } |
|
63 | 64 | |
64 | 65 | $this->log_table = config($this->index . '.log_table'); |
65 | 66 | |
@@ -74,11 +75,12 @@ discard block |
||
74 | 75 | ' AND connection = ' . '\'' . $connection . '\'' |
75 | 76 | ); |
76 | 77 | |
77 | - if(empty($log_records)) |
|
78 | - \Artisan::call('quota:reset', [ |
|
78 | + if(empty($log_records)) { |
|
79 | + \Artisan::call('quota:reset', [ |
|
79 | 80 | 'date' => $date, |
80 | 81 | 'connection' => $connection |
81 | 82 | ]); |
83 | + } |
|
82 | 84 | } |
83 | 85 | |
84 | 86 | public function enforce() |
@@ -163,8 +165,7 @@ discard block |
||
163 | 165 | throw new \ErrorException( |
164 | 166 | __CLASS__ . '::' . __FUNCTION__ . |
165 | 167 | ' Overquota. Exceeded daily limit: ' . $this->limit); |
166 | - } |
|
167 | - else |
|
168 | + } else |
|
168 | 169 | { |
169 | 170 | $this->hit($stats->hits); |
170 | 171 | $result = true; |
@@ -98,12 +98,12 @@ |
||
98 | 98 | return $result; |
99 | 99 | } |
100 | 100 | |
101 | - /** |
|
102 | - * Public interface. |
|
103 | - * |
|
104 | - * NOTE: this class and method are really abstract, |
|
105 | - * but we leave it instantiable for easier testing. |
|
106 | - */ |
|
101 | + /** |
|
102 | + * Public interface. |
|
103 | + * |
|
104 | + * NOTE: this class and method are really abstract, |
|
105 | + * but we leave it instantiable for easier testing. |
|
106 | + */ |
|
107 | 107 | public function enforce() |
108 | 108 | { |
109 | 109 | //Override this in descendants. |
@@ -60,11 +60,11 @@ discard block |
||
60 | 60 | public function __construct($connection) |
61 | 61 | { |
62 | 62 | $this->connection = $connection; |
63 | - $this->index = 'quota.connections.' . $connection; |
|
63 | + $this->index = 'quota.connections.'.$connection; |
|
64 | 64 | |
65 | - $this->limit = config($this->index . '.limit'); |
|
65 | + $this->limit = config($this->index.'.limit'); |
|
66 | 66 | |
67 | - $period = config($this->index . '.period'); |
|
67 | + $period = config($this->index.'.period'); |
|
68 | 68 | $this->setPeriod($period); |
69 | 69 | } |
70 | 70 | |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | $result = false; |
94 | 94 | $constants = $this->validPeriods(); |
95 | 95 | $values = array_values($constants); |
96 | - if(in_array($period, $values)) |
|
96 | + if (in_array($period, $values)) |
|
97 | 97 | $result = true; |
98 | 98 | return $result; |
99 | 99 | } |
@@ -193,15 +193,15 @@ discard block |
||
193 | 193 | */ |
194 | 194 | public function setPeriod($period) |
195 | 195 | { |
196 | - if(! $this->validatePeriod($period)) |
|
196 | + if (!$this->validatePeriod($period)) |
|
197 | 197 | { |
198 | 198 | $expected = $this->validPeriods(); |
199 | 199 | |
200 | 200 | throw new \InvalidArgumentException( |
201 | 201 | __CLASS__.'::'.__FUNCTION__. |
202 | - ' Invalid period: ' . $period . |
|
203 | - ' in connection configuration: ' . $this->connection . |
|
204 | - ' expected one of: ' . PHP_EOL . print_r($expected,1)); |
|
202 | + ' Invalid period: '.$period. |
|
203 | + ' in connection configuration: '.$this->connection. |
|
204 | + ' expected one of: '.PHP_EOL.print_r($expected, 1)); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | $this->period = $period; |
@@ -93,8 +93,9 @@ |
||
93 | 93 | $result = false; |
94 | 94 | $constants = $this->validPeriods(); |
95 | 95 | $values = array_values($constants); |
96 | - if(in_array($period, $values)) |
|
97 | - $result = true; |
|
96 | + if(in_array($period, $values)) { |
|
97 | + $result = true; |
|
98 | + } |
|
98 | 99 | return $result; |
99 | 100 | } |
100 | 101 |
@@ -88,13 +88,13 @@ discard block |
||
88 | 88 | { |
89 | 89 | parent::__construct($connection); |
90 | 90 | |
91 | - $this->driver = config($this->index . '.driver'); |
|
91 | + $this->driver = config($this->index.'.driver'); |
|
92 | 92 | |
93 | 93 | //TODO: REFACTOR for multiple storage types. |
94 | - if($this->driver != 'quota.storage.file') |
|
95 | - throw new \Exception('Driver: ' . $this->driver . ' not supported.'); |
|
94 | + if ($this->driver != 'quota.storage.file') |
|
95 | + throw new \Exception('Driver: '.$this->driver.' not supported.'); |
|
96 | 96 | |
97 | - $this->path = config($this->index . '.path'); |
|
97 | + $this->path = config($this->index.'.path'); |
|
98 | 98 | $this->storage = app($this->driver, ['path' => $this->path]); |
99 | 99 | //END REFACTOR |
100 | 100 | |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | ['limit' => $this->limit, 'period' => $this->period]); |
104 | 104 | |
105 | 105 | //Resolve bucket via IoC container. |
106 | - $capacity = config($this->index . '.capacity'); |
|
106 | + $capacity = config($this->index.'.capacity'); |
|
107 | 107 | $this->bucket = app('quota.bucket', [ |
108 | 108 | 'capacity' => $capacity, |
109 | 109 | 'rate' => $this->rate, |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | $this->bucket->bootstrap($capacity); |
115 | 115 | |
116 | 116 | //Optionally enclose bucket within a blocking consumer. |
117 | - if(config($this->index . '.block') == TRUE) |
|
117 | + if (config($this->index.'.block') == TRUE) |
|
118 | 118 | { |
119 | 119 | $this->blocker = app('quota.blocker', ['bucket' => $this->bucket]); |
120 | 120 | } |
@@ -175,15 +175,15 @@ discard block |
||
175 | 175 | */ |
176 | 176 | public function consume($tokens = 1) |
177 | 177 | { |
178 | - if(isset($this->bucket)) |
|
178 | + if (isset($this->bucket)) |
|
179 | 179 | { |
180 | - if (! isset($this->blocker)) |
|
180 | + if (!isset($this->blocker)) |
|
181 | 181 | { |
182 | 182 | $result = $this->bucket->consume($tokens, $seconds); |
183 | - if( $result === false) |
|
183 | + if ($result === false) |
|
184 | 184 | throw new \ErrorException( |
185 | - __CLASS__ . '::' . __FUNCTION__ . |
|
186 | - ' Overquota. Exceeded bandwidth. Wait ' . $seconds . ' seconds.'); |
|
185 | + __CLASS__.'::'.__FUNCTION__. |
|
186 | + ' Overquota. Exceeded bandwidth. Wait '.$seconds.' seconds.'); |
|
187 | 187 | } |
188 | 188 | else |
189 | 189 | { |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | */ |
222 | 222 | public function remove() |
223 | 223 | { |
224 | - if(isset($this->storage)) |
|
224 | + if (isset($this->storage)) |
|
225 | 225 | { |
226 | 226 | $this->storage->remove(); |
227 | 227 | unset($this->storage); |
@@ -91,8 +91,9 @@ discard block |
||
91 | 91 | $this->driver = config($this->index . '.driver'); |
92 | 92 | |
93 | 93 | //TODO: REFACTOR for multiple storage types. |
94 | - if($this->driver != 'quota.storage.file') |
|
95 | - throw new \Exception('Driver: ' . $this->driver . ' not supported.'); |
|
94 | + if($this->driver != 'quota.storage.file') { |
|
95 | + throw new \Exception('Driver: ' . $this->driver . ' not supported.'); |
|
96 | + } |
|
96 | 97 | |
97 | 98 | $this->path = config($this->index . '.path'); |
98 | 99 | $this->storage = app($this->driver, ['path' => $this->path]); |
@@ -180,12 +181,12 @@ discard block |
||
180 | 181 | if (! isset($this->blocker)) |
181 | 182 | { |
182 | 183 | $result = $this->bucket->consume($tokens, $seconds); |
183 | - if( $result === false) |
|
184 | - throw new \ErrorException( |
|
184 | + if( $result === false) { |
|
185 | + throw new \ErrorException( |
|
185 | 186 | __CLASS__ . '::' . __FUNCTION__ . |
186 | 187 | ' Overquota. Exceeded bandwidth. Wait ' . $seconds . ' seconds.'); |
187 | - } |
|
188 | - else |
|
188 | + } |
|
189 | + } else |
|
189 | 190 | { |
190 | 191 | $result = $this->blocker->consume($tokens); |
191 | 192 | } |
@@ -203,14 +204,17 @@ discard block |
||
203 | 204 | */ |
204 | 205 | public function release() |
205 | 206 | { |
206 | - if (isset($this->blocker)) |
|
207 | - unset($this->blocker); |
|
207 | + if (isset($this->blocker)) { |
|
208 | + unset($this->blocker); |
|
209 | + } |
|
208 | 210 | |
209 | - if (isset($this->bucket)) |
|
210 | - unset($this->bucket); |
|
211 | + if (isset($this->bucket)) { |
|
212 | + unset($this->bucket); |
|
213 | + } |
|
211 | 214 | |
212 | - if (isset($this->rate)) |
|
213 | - unset($this->rate); |
|
215 | + if (isset($this->rate)) { |
|
216 | + unset($this->rate); |
|
217 | + } |
|
214 | 218 | } |
215 | 219 | |
216 | 220 | /** |
@@ -87,15 +87,15 @@ discard block |
||
87 | 87 | } |
88 | 88 | } |
89 | 89 | |
90 | - /** |
|
91 | - * Register a database migration path. |
|
92 | - * |
|
93 | - * NOTE: This function is already part of 5.4 |
|
94 | - * it is backported here for 5.2 |
|
95 | - * |
|
96 | - * @param array|string $paths |
|
97 | - * @return void |
|
98 | - */ |
|
90 | + /** |
|
91 | + * Register a database migration path. |
|
92 | + * |
|
93 | + * NOTE: This function is already part of 5.4 |
|
94 | + * it is backported here for 5.2 |
|
95 | + * |
|
96 | + * @param array|string $paths |
|
97 | + * @return void |
|
98 | + */ |
|
99 | 99 | //protected function loadMigrationsFrom($paths) |
100 | 100 | //{ |
101 | 101 | // dump(__CLASS__.'::'.__FUNCTION__); |
@@ -146,20 +146,20 @@ discard block |
||
146 | 146 | public function bindInterfaces() |
147 | 147 | { |
148 | 148 | $this->app->when(RateFactory::class) |
149 | - ->needs('Projectmentor\Quota\Contracts\PayloadInterface') |
|
150 | - ->give(RateData::class); |
|
149 | + ->needs('Projectmentor\Quota\Contracts\PayloadInterface') |
|
150 | + ->give(RateData::class); |
|
151 | 151 | |
152 | 152 | $this->app->when(FileStorageFactory::class) |
153 | - ->needs('Projectmentor\Quota\Contracts\PayloadInterface') |
|
154 | - ->give(FileStorageData::class); |
|
153 | + ->needs('Projectmentor\Quota\Contracts\PayloadInterface') |
|
154 | + ->give(FileStorageData::class); |
|
155 | 155 | |
156 | 156 | $this->app->when(TokenBucketFactory::class) |
157 | - ->needs('Projectmentor\Quota\Contracts\PayloadInterface') |
|
158 | - ->give(TokenBucketData::class); |
|
157 | + ->needs('Projectmentor\Quota\Contracts\PayloadInterface') |
|
158 | + ->give(TokenBucketData::class); |
|
159 | 159 | |
160 | 160 | $this->app->when(BlockingConsumerFactory::class) |
161 | - ->needs('Projectmentor\Quota\Contracts\PayloadInterface') |
|
162 | - ->give(BlockingConsumerData::class); |
|
161 | + ->needs('Projectmentor\Quota\Contracts\PayloadInterface') |
|
162 | + ->give(BlockingConsumerData::class); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -168,19 +168,19 @@ discard block |
||
168 | 168 | */ |
169 | 169 | protected function registerFactories() |
170 | 170 | { |
171 | - $this->app->singleton('quota.factory.rate', function ($app) { |
|
171 | + $this->app->singleton('quota.factory.rate', function($app) { |
|
172 | 172 | return new RateFactory; |
173 | 173 | }); |
174 | 174 | |
175 | - $this->app->singleton('quota.factory.storage.file', function ($app) { |
|
175 | + $this->app->singleton('quota.factory.storage.file', function($app) { |
|
176 | 176 | return new FileStorageFactory; |
177 | 177 | }); |
178 | 178 | |
179 | - $this->app->singleton('quota.factory.tokenbucket', function ($app) { |
|
179 | + $this->app->singleton('quota.factory.tokenbucket', function($app) { |
|
180 | 180 | return new TokenBucketFactory; |
181 | 181 | }); |
182 | 182 | |
183 | - $this->app->singleton('quota.factory.blockingconsumer', function ($app) { |
|
183 | + $this->app->singleton('quota.factory.blockingconsumer', function($app) { |
|
184 | 184 | return new BlockingConsumerFactory; |
185 | 185 | }); |
186 | 186 | |
@@ -208,19 +208,19 @@ discard block |
||
208 | 208 | */ |
209 | 209 | protected function registerClasses() |
210 | 210 | { |
211 | - $this->app->bind('quota.storage.file', function($app, $params){ |
|
211 | + $this->app->bind('quota.storage.file', function($app, $params) { |
|
212 | 212 | return new FileStorage($params['path']); |
213 | 213 | }); |
214 | 214 | |
215 | - $this->app->bind('quota.rate', function($app, $params){ |
|
215 | + $this->app->bind('quota.rate', function($app, $params) { |
|
216 | 216 | return new Rate($params['limit'], $params['period']); |
217 | 217 | }); |
218 | 218 | |
219 | - $this->app->bind('quota.bucket', function($app, $params){ |
|
219 | + $this->app->bind('quota.bucket', function($app, $params) { |
|
220 | 220 | return new TokenBucket($params['capacity'], $params['rate'], $params['storage']); |
221 | 221 | }); |
222 | 222 | |
223 | - $this->app->bind('quota.blocker', function($app, $params){ |
|
223 | + $this->app->bind('quota.blocker', function($app, $params) { |
|
224 | 224 | return new BlockingConsumer($params['bucket']); |
225 | 225 | }); |
226 | 226 |
@@ -84,23 +84,23 @@ |
||
84 | 84 | if(! $this->sqliteUpdateDidChange($changes)) |
85 | 85 | { |
86 | 86 | $sql = 'INSERT INTO quotalog' . |
87 | - ' (' . |
|
88 | - ' `date`' . |
|
89 | - ', `connection`' . |
|
90 | - ', `hits`' . |
|
91 | - ', `misses`' . |
|
92 | - ', `created_at`' . |
|
93 | - ', `updated_at`' . |
|
94 | - ')' . |
|
95 | - ' VALUES' . |
|
96 | - ' (' . |
|
97 | - ' :date' . |
|
98 | - ', :connection' . |
|
99 | - ', :hits' . |
|
100 | - ', :misses' . |
|
101 | - ', :created_at' . |
|
102 | - ', :updated_at' . |
|
103 | - ')'; |
|
87 | + ' (' . |
|
88 | + ' `date`' . |
|
89 | + ', `connection`' . |
|
90 | + ', `hits`' . |
|
91 | + ', `misses`' . |
|
92 | + ', `created_at`' . |
|
93 | + ', `updated_at`' . |
|
94 | + ')' . |
|
95 | + ' VALUES' . |
|
96 | + ' (' . |
|
97 | + ' :date' . |
|
98 | + ', :connection' . |
|
99 | + ', :hits' . |
|
100 | + ', :misses' . |
|
101 | + ', :created_at' . |
|
102 | + ', :updated_at' . |
|
103 | + ')'; |
|
104 | 104 | |
105 | 105 | $this->doUpsertStatement($sql); |
106 | 106 | } |
@@ -50,66 +50,66 @@ |
||
50 | 50 | { |
51 | 51 | switch(DB::connection()->getPDO()->getAttribute(\PDO::ATTR_DRIVER_NAME)) |
52 | 52 | { |
53 | - case 'mysql': |
|
54 | - |
|
55 | - $sql = 'INSERT INTO quotalog' . |
|
56 | - ' (date, connection, hits, misses, created_at, updated_at)' . |
|
57 | - ' VALUES' . |
|
58 | - ' ( :date, :connection, :hits, :misses, :created_at, :updated_at)' . |
|
59 | - ' ON DUPLICATE KEY UPDATE' . |
|
60 | - ' hits = VALUES(hits),' . |
|
61 | - ' misses = VALUES(misses),' . |
|
62 | - ' updated_at = VALUES(updated_at)'; |
|
63 | - |
|
64 | - $this->doUpsertStatement($sql); |
|
65 | - |
|
66 | - break; |
|
67 | - case 'sqlite': |
|
68 | - |
|
69 | - $date = $this->argument('date'); |
|
70 | - $connection = $this->argument('connection'); |
|
71 | - |
|
72 | - $sql = 'UPDATE quotalog' . |
|
73 | - ' SET `date` = :date' . |
|
74 | - ', `connection` = :connection' . |
|
75 | - ', `hits` = :hits' . |
|
76 | - ', `misses` = :misses' . |
|
77 | - ', `updated_at` = :updated_at' . |
|
78 | - ' WHERE `date` = ' . '\''. $date . '\'' . |
|
79 | - ' AND `connection` = ' . '\'' . $connection . '\''; |
|
80 | - |
|
81 | - $this->doUpdateStatement($sql); |
|
82 | - |
|
83 | - $changes = DB::select('SELECT changes()'); |
|
84 | - if(! $this->sqliteUpdateDidChange($changes)) |
|
85 | - { |
|
53 | + case 'mysql': |
|
54 | + |
|
86 | 55 | $sql = 'INSERT INTO quotalog' . |
87 | - ' (' . |
|
88 | - ' `date`' . |
|
89 | - ', `connection`' . |
|
90 | - ', `hits`' . |
|
91 | - ', `misses`' . |
|
92 | - ', `created_at`' . |
|
93 | - ', `updated_at`' . |
|
94 | - ')' . |
|
95 | - ' VALUES' . |
|
96 | - ' (' . |
|
97 | - ' :date' . |
|
98 | - ', :connection' . |
|
99 | - ', :hits' . |
|
100 | - ', :misses' . |
|
101 | - ', :created_at' . |
|
102 | - ', :updated_at' . |
|
103 | - ')'; |
|
56 | + ' (date, connection, hits, misses, created_at, updated_at)' . |
|
57 | + ' VALUES' . |
|
58 | + ' ( :date, :connection, :hits, :misses, :created_at, :updated_at)' . |
|
59 | + ' ON DUPLICATE KEY UPDATE' . |
|
60 | + ' hits = VALUES(hits),' . |
|
61 | + ' misses = VALUES(misses),' . |
|
62 | + ' updated_at = VALUES(updated_at)'; |
|
104 | 63 | |
105 | 64 | $this->doUpsertStatement($sql); |
106 | - } |
|
107 | - break; |
|
108 | 65 | |
109 | - default: |
|
110 | - throw new \ErrorException( |
|
111 | - __CLASS__.'::'.__FUNCTION__. |
|
112 | - ' Driver: ' . $driver . ' not supported.'); |
|
66 | + break; |
|
67 | + case 'sqlite': |
|
68 | + |
|
69 | + $date = $this->argument('date'); |
|
70 | + $connection = $this->argument('connection'); |
|
71 | + |
|
72 | + $sql = 'UPDATE quotalog' . |
|
73 | + ' SET `date` = :date' . |
|
74 | + ', `connection` = :connection' . |
|
75 | + ', `hits` = :hits' . |
|
76 | + ', `misses` = :misses' . |
|
77 | + ', `updated_at` = :updated_at' . |
|
78 | + ' WHERE `date` = ' . '\''. $date . '\'' . |
|
79 | + ' AND `connection` = ' . '\'' . $connection . '\''; |
|
80 | + |
|
81 | + $this->doUpdateStatement($sql); |
|
82 | + |
|
83 | + $changes = DB::select('SELECT changes()'); |
|
84 | + if(! $this->sqliteUpdateDidChange($changes)) |
|
85 | + { |
|
86 | + $sql = 'INSERT INTO quotalog' . |
|
87 | + ' (' . |
|
88 | + ' `date`' . |
|
89 | + ', `connection`' . |
|
90 | + ', `hits`' . |
|
91 | + ', `misses`' . |
|
92 | + ', `created_at`' . |
|
93 | + ', `updated_at`' . |
|
94 | + ')' . |
|
95 | + ' VALUES' . |
|
96 | + ' (' . |
|
97 | + ' :date' . |
|
98 | + ', :connection' . |
|
99 | + ', :hits' . |
|
100 | + ', :misses' . |
|
101 | + ', :created_at' . |
|
102 | + ', :updated_at' . |
|
103 | + ')'; |
|
104 | + |
|
105 | + $this->doUpsertStatement($sql); |
|
106 | + } |
|
107 | + break; |
|
108 | + |
|
109 | + default: |
|
110 | + throw new \ErrorException( |
|
111 | + __CLASS__.'::'.__FUNCTION__. |
|
112 | + ' Driver: ' . $driver . ' not supported.'); |
|
113 | 113 | } |
114 | 114 | } |
115 | 115 |
@@ -48,17 +48,17 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public function handle() |
50 | 50 | { |
51 | - switch(DB::connection()->getPDO()->getAttribute(\PDO::ATTR_DRIVER_NAME)) |
|
51 | + switch (DB::connection()->getPDO()->getAttribute(\PDO::ATTR_DRIVER_NAME)) |
|
52 | 52 | { |
53 | 53 | case 'mysql': |
54 | 54 | |
55 | - $sql = 'INSERT INTO quotalog' . |
|
56 | - ' (date, connection, hits, misses, created_at, updated_at)' . |
|
57 | - ' VALUES' . |
|
58 | - ' ( :date, :connection, :hits, :misses, :created_at, :updated_at)' . |
|
59 | - ' ON DUPLICATE KEY UPDATE' . |
|
60 | - ' hits = VALUES(hits),' . |
|
61 | - ' misses = VALUES(misses),' . |
|
55 | + $sql = 'INSERT INTO quotalog'. |
|
56 | + ' (date, connection, hits, misses, created_at, updated_at)'. |
|
57 | + ' VALUES'. |
|
58 | + ' ( :date, :connection, :hits, :misses, :created_at, :updated_at)'. |
|
59 | + ' ON DUPLICATE KEY UPDATE'. |
|
60 | + ' hits = VALUES(hits),'. |
|
61 | + ' misses = VALUES(misses),'. |
|
62 | 62 | ' updated_at = VALUES(updated_at)'; |
63 | 63 | |
64 | 64 | $this->doUpsertStatement($sql); |
@@ -69,37 +69,37 @@ discard block |
||
69 | 69 | $date = $this->argument('date'); |
70 | 70 | $connection = $this->argument('connection'); |
71 | 71 | |
72 | - $sql = 'UPDATE quotalog' . |
|
73 | - ' SET `date` = :date' . |
|
74 | - ', `connection` = :connection' . |
|
75 | - ', `hits` = :hits' . |
|
76 | - ', `misses` = :misses' . |
|
77 | - ', `updated_at` = :updated_at' . |
|
78 | - ' WHERE `date` = ' . '\''. $date . '\'' . |
|
79 | - ' AND `connection` = ' . '\'' . $connection . '\''; |
|
72 | + $sql = 'UPDATE quotalog'. |
|
73 | + ' SET `date` = :date'. |
|
74 | + ', `connection` = :connection'. |
|
75 | + ', `hits` = :hits'. |
|
76 | + ', `misses` = :misses'. |
|
77 | + ', `updated_at` = :updated_at'. |
|
78 | + ' WHERE `date` = '.'\''.$date.'\''. |
|
79 | + ' AND `connection` = '.'\''.$connection.'\''; |
|
80 | 80 | |
81 | 81 | $this->doUpdateStatement($sql); |
82 | 82 | |
83 | 83 | $changes = DB::select('SELECT changes()'); |
84 | - if(! $this->sqliteUpdateDidChange($changes)) |
|
84 | + if (!$this->sqliteUpdateDidChange($changes)) |
|
85 | 85 | { |
86 | - $sql = 'INSERT INTO quotalog' . |
|
87 | - ' (' . |
|
88 | - ' `date`' . |
|
89 | - ', `connection`' . |
|
90 | - ', `hits`' . |
|
91 | - ', `misses`' . |
|
92 | - ', `created_at`' . |
|
93 | - ', `updated_at`' . |
|
94 | - ')' . |
|
95 | - ' VALUES' . |
|
96 | - ' (' . |
|
97 | - ' :date' . |
|
98 | - ', :connection' . |
|
99 | - ', :hits' . |
|
100 | - ', :misses' . |
|
101 | - ', :created_at' . |
|
102 | - ', :updated_at' . |
|
86 | + $sql = 'INSERT INTO quotalog'. |
|
87 | + ' ('. |
|
88 | + ' `date`'. |
|
89 | + ', `connection`'. |
|
90 | + ', `hits`'. |
|
91 | + ', `misses`'. |
|
92 | + ', `created_at`'. |
|
93 | + ', `updated_at`'. |
|
94 | + ')'. |
|
95 | + ' VALUES'. |
|
96 | + ' ('. |
|
97 | + ' :date'. |
|
98 | + ', :connection'. |
|
99 | + ', :hits'. |
|
100 | + ', :misses'. |
|
101 | + ', :created_at'. |
|
102 | + ', :updated_at'. |
|
103 | 103 | ')'; |
104 | 104 | |
105 | 105 | $this->doUpsertStatement($sql); |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | default: |
110 | 110 | throw new \ErrorException( |
111 | 111 | __CLASS__.'::'.__FUNCTION__. |
112 | - ' Driver: ' . $driver . ' not supported.'); |
|
112 | + ' Driver: '.$driver.' not supported.'); |
|
113 | 113 | } |
114 | 114 | } |
115 | 115 |
@@ -30,10 +30,10 @@ |
||
30 | 30 | */ |
31 | 31 | public function up() |
32 | 32 | { |
33 | - Schema::create('quotalog', function (Blueprint $table) { |
|
33 | + Schema::create('quotalog', function(Blueprint $table) { |
|
34 | 34 | $table->increments('id'); |
35 | 35 | $table->date('date'); |
36 | - $table->string('connection'); //@See config/quota.php |
|
36 | + $table->string('connection'); //@See config/quota.php |
|
37 | 37 | $table->integer('hits')->default(0); |
38 | 38 | $table->integer('misses')->default(0); |
39 | 39 |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | |
36 | 36 | 'bandwidth' => [ |
37 | 37 | 'limit' => env('QUOTA_BANDWIDTH_LIMIT', 60), |
38 | - 'period' => env('QUOTA_BANDWIDTH_PERIOD','second'), |
|
38 | + 'period' => env('QUOTA_BANDWIDTH_PERIOD', 'second'), |
|
39 | 39 | 'driver' => 'quota.storage.file', |
40 | 40 | 'path' => env('QUOTA_BANDWIDTH_PATH', '/tmp/bandwidth.quota'), |
41 | 41 | 'capacity' => env('QUOTA_BANDWIDTH_CAPACITY', 60), |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | |
45 | 45 | 'daily' => [ |
46 | 46 | 'limit' => env('QUOTA_DAILY_LIMIT', 2500), |
47 | - 'period' => env('QUOTA_DAILY_PERIOD','day'), |
|
47 | + 'period' => env('QUOTA_DAILY_PERIOD', 'day'), |
|
48 | 48 | 'log_table' => env('QUOTA_DAILY_LOG_TABLE', 'quotalog'), |
49 | 49 | 'timezone' => env('QUOTA_DAILY_TIMEZONE', 'America/New_York'), |
50 | 50 | ], |