| 
									
										
										
										
											2016-06-10 21:00:00 +02:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * ImportJob.php | 
					
						
							| 
									
										
										
										
											2017-10-21 08:40:00 +02:00
										 |  |  |  * Copyright (c) 2017 thegrumpydictator@gmail.com | 
					
						
							| 
									
										
										
										
											2016-06-10 21:00:00 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2017-10-21 08:40:00 +02:00
										 |  |  |  * This file is part of Firefly III. | 
					
						
							| 
									
										
										
										
											2016-10-05 06:52:15 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2017-10-21 08:40:00 +02:00
										 |  |  |  * Firefly III is free software: you can redistribute it and/or modify | 
					
						
							|  |  |  |  * it under the terms of the GNU General Public License as published by | 
					
						
							|  |  |  |  * the Free Software Foundation, either version 3 of the License, or | 
					
						
							|  |  |  |  * (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Firefly III is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							| 
									
										
										
										
											2017-12-17 14:44:05 +01:00
										 |  |  |  * along with Firefly III. If not, see <http://www.gnu.org/licenses/>. | 
					
						
							| 
									
										
										
										
											2016-06-10 21:00:00 +02:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-03-24 15:15:12 +01:00
										 |  |  | declare(strict_types=1); | 
					
						
							| 
									
										
										
										
											2016-06-10 21:00:00 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace FireflyIII\Models; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-25 20:03:48 +02:00
										 |  |  | use Carbon\Carbon; | 
					
						
							| 
									
										
										
										
											2018-03-10 20:25:42 +01:00
										 |  |  | use FireflyIII\User; | 
					
						
							| 
									
										
										
										
											2016-06-10 21:00:00 +02:00
										 |  |  | use Illuminate\Database\Eloquent\Model; | 
					
						
							| 
									
										
										
										
											2018-08-04 17:30:06 +02:00
										 |  |  | use Illuminate\Database\Eloquent\Relations\BelongsTo; | 
					
						
							| 
									
										
										
										
											2018-08-06 19:14:30 +02:00
										 |  |  | use Illuminate\Database\Eloquent\Relations\MorphMany; | 
					
						
							| 
									
										
										
										
											2016-06-10 21:00:00 +02:00
										 |  |  | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-18 20:06:08 +01:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2017-11-15 12:25:49 +01:00
										 |  |  |  * Class ImportJob. | 
					
						
							| 
									
										
										
										
											2018-03-10 22:38:20 +01:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-05-19 21:13:00 +02:00
										 |  |  |  * @property array  $transactions | 
					
						
							|  |  |  |  * @property array  $configuration | 
					
						
							|  |  |  |  * @property User   $user | 
					
						
							|  |  |  |  * @property int    $user_id | 
					
						
							|  |  |  |  * @property string $status | 
					
						
							|  |  |  |  * @property string $stage | 
					
						
							| 
									
										
										
										
											2018-05-20 16:26:27 +02:00
										 |  |  |  * @property string $key | 
					
						
							|  |  |  |  * @property string $provider | 
					
						
							|  |  |  |  * @property string $file_type | 
					
						
							| 
									
										
										
										
											2018-05-23 12:36:12 +02:00
										 |  |  |  * @property int    $tag_id | 
					
						
							|  |  |  |  * @property Tag    $tag | 
					
						
							| 
									
										
										
										
											2018-07-15 09:27:38 +02:00
										 |  |  |  * @property array  $errors | 
					
						
							| 
									
										
										
										
											2018-07-22 18:50:27 +02:00
										 |  |  |  * @property array  extended_status | 
					
						
							| 
									
										
										
										
											2018-08-06 19:14:30 +02:00
										 |  |  |  * @property int    id | 
					
						
							| 
									
										
										
										
											2018-10-25 20:03:48 +02:00
										 |  |  |  * @property Carbon $created_at | 
					
						
							| 
									
										
										
										
											2018-12-08 08:22:53 +01:00
										 |  |  |  * @property Carbon $updated_at | 
					
						
							| 
									
										
										
										
											2019-03-05 17:26:49 +01:00
										 |  |  |  * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Attachment[] $attachments | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ImportJob newModelQuery() | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ImportJob newQuery() | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ImportJob query() | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ImportJob whereConfiguration($value) | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ImportJob whereCreatedAt($value) | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ImportJob whereErrors($value) | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ImportJob whereExtendedStatus($value) | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ImportJob whereFileType($value) | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ImportJob whereId($value) | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ImportJob whereKey($value) | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ImportJob whereProvider($value) | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ImportJob whereStage($value) | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ImportJob whereStatus($value) | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ImportJob whereTagId($value) | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ImportJob whereTransactions($value) | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ImportJob whereUpdatedAt($value) | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ImportJob whereUserId($value) | 
					
						
							|  |  |  |  * @mixin \Eloquent | 
					
						
							| 
									
										
										
										
											2016-11-18 20:06:08 +01:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2016-06-10 21:00:00 +02:00
										 |  |  | class ImportJob extends Model | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-04-29 20:01:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-17 14:30:53 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-12-23 17:42:07 +01:00
										 |  |  |      * The attributes that should be casted to native types. | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2017-12-17 14:30:53 +01:00
										 |  |  |      * @var array | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2017-12-23 17:42:07 +01:00
										 |  |  |     protected $casts | 
					
						
							| 
									
										
										
										
											2016-08-24 19:33:58 +02:00
										 |  |  |         = [ | 
					
						
							| 
									
										
										
										
											2018-10-07 15:55:44 +02:00
										 |  |  |             'user_id'         => 'int', | 
					
						
							| 
									
										
										
										
											2018-04-29 18:07:14 +02:00
										 |  |  |             'created_at'      => 'datetime', | 
					
						
							|  |  |  |             'updated_at'      => 'datetime', | 
					
						
							|  |  |  |             'configuration'   => 'array', | 
					
						
							|  |  |  |             'extended_status' => 'array', | 
					
						
							|  |  |  |             'transactions'    => 'array', | 
					
						
							| 
									
										
										
										
											2018-05-03 17:23:16 +02:00
										 |  |  |             'errors'          => 'array', | 
					
						
							| 
									
										
										
										
											2016-08-24 19:33:58 +02:00
										 |  |  |         ]; | 
					
						
							| 
									
										
										
										
											2018-08-04 17:30:06 +02:00
										 |  |  |     /** @var array Fields that can be filled */ | 
					
						
							| 
									
										
										
										
											2018-05-03 17:23:16 +02:00
										 |  |  |     protected $fillable = ['key', 'user_id', 'file_type', 'provider', 'status', 'stage', 'configuration', 'extended_status', 'transactions', 'errors']; | 
					
						
							| 
									
										
										
										
											2016-08-24 19:33:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-10 21:00:00 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2018-08-04 17:30:06 +02:00
										 |  |  |      * Route binder. Converts the key in the URL to the specified object (or throw 404). | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2016-06-10 21:00:00 +02:00
										 |  |  |      * @param $value | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return mixed | 
					
						
							| 
									
										
										
										
											2017-11-15 12:25:49 +01:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2016-06-10 21:00:00 +02:00
										 |  |  |      * @throws NotFoundHttpException | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-02-09 19:24:15 +01:00
										 |  |  |     public static function routeBinder(string $value): ImportJob | 
					
						
							| 
									
										
										
										
											2016-06-10 21:00:00 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-02-09 19:28:16 +01:00
										 |  |  |         if (auth()->check()) { | 
					
						
							| 
									
										
										
										
											2018-08-06 19:14:30 +02:00
										 |  |  |             $key = trim($value); | 
					
						
							| 
									
										
										
										
											2018-07-22 16:35:46 +02:00
										 |  |  |             /** @var User $user */ | 
					
						
							|  |  |  |             $user = auth()->user(); | 
					
						
							|  |  |  |             /** @var ImportJob $importJob */ | 
					
						
							|  |  |  |             $importJob = $user->importJobs()->where('key', $key)->first(); | 
					
						
							| 
									
										
										
										
											2017-12-25 08:45:23 +01:00
										 |  |  |             if (null !== $importJob) { | 
					
						
							|  |  |  |                 return $importJob; | 
					
						
							| 
									
										
										
										
											2016-06-10 21:00:00 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         throw new NotFoundHttpException; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-27 15:15:46 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-12-25 08:45:23 +01:00
										 |  |  |      * @codeCoverageIgnore | 
					
						
							| 
									
										
										
										
											2018-08-06 19:14:30 +02:00
										 |  |  |      * @return MorphMany | 
					
						
							| 
									
										
										
										
											2016-06-27 15:15:46 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-08-06 19:14:30 +02:00
										 |  |  |     public function attachments(): MorphMany | 
					
						
							| 
									
										
										
										
											2016-06-27 15:15:46 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-05-19 21:13:00 +02:00
										 |  |  |         return $this->morphMany(Attachment::class, 'attachable'); | 
					
						
							| 
									
										
										
										
											2016-06-27 15:15:46 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-05-03 17:23:16 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @codeCoverageIgnore | 
					
						
							| 
									
										
										
										
											2018-08-04 17:30:06 +02:00
										 |  |  |      * @return BelongsTo | 
					
						
							| 
									
										
										
										
											2018-05-03 17:23:16 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-08-04 17:30:06 +02:00
										 |  |  |     public function tag(): BelongsTo | 
					
						
							| 
									
										
										
										
											2018-05-03 17:23:16 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         return $this->belongsTo(Tag::class); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-05-19 21:13:00 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @codeCoverageIgnore | 
					
						
							| 
									
										
										
										
											2018-08-04 17:30:06 +02:00
										 |  |  |      * @return BelongsTo | 
					
						
							| 
									
										
										
										
											2018-05-19 21:13:00 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-08-04 17:30:06 +02:00
										 |  |  |     public function user(): BelongsTo | 
					
						
							| 
									
										
										
										
											2018-05-19 21:13:00 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         return $this->belongsTo(User::class); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-06-10 21:00:00 +02:00
										 |  |  | } |