|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* GitScrum v0.1. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Renato Marinho <renato.marinho> |
|
6
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace GitScrum\Observers; |
|
10
|
|
|
|
|
11
|
|
|
use GitScrum\Models\Issue; |
|
12
|
|
|
use GitScrum\Models\UserStory; |
|
13
|
|
|
use GitScrum\Models\ConfigStatus; |
|
14
|
|
|
use GitScrum\Models\Sprint; |
|
15
|
|
|
use GitScrum\Models\Status; |
|
16
|
|
|
use GitScrum\Classes\Helper; |
|
17
|
|
|
use Auth; |
|
18
|
|
|
|
|
19
|
|
|
class IssueObserver |
|
20
|
|
|
{ |
|
21
|
|
|
public function creating(Issue $issue) |
|
22
|
|
|
{ |
|
23
|
|
|
if (isset($issue->product_backlog_id)) { |
|
24
|
|
|
$product_backlog_id = $issue->product_backlog_id; |
|
|
|
|
|
|
25
|
|
|
} else { |
|
26
|
|
|
try { |
|
27
|
|
|
$product_backlog_id = UserStory::find($issue->user_story_id)->product_backlog_id; |
|
|
|
|
|
|
28
|
|
|
} catch (\Exception $e) { |
|
29
|
|
|
$product_backlog_id = $issue->sprint()->first()->product_backlog_id; |
|
30
|
|
|
} |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
$issue->slug = Helper::slug($issue->title); |
|
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
if (!isset($issue->user_id)) { |
|
36
|
|
|
$issue->user_id = Auth::user()->id; |
|
|
|
|
|
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
if (!isset($issue->config_status_id)) { |
|
40
|
|
|
$issue->config_status_id = ConfigStatus::where('default', '=', 1)->first()->id; |
|
|
|
|
|
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
$issue->product_backlog_id = $product_backlog_id; |
|
|
|
|
|
|
44
|
|
|
$issue->sprint_id = intval($issue->sprint_id)?$issue->sprint_id:null; |
|
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
$tmp = app(Auth::user()->provider)->createOrUpdateIssue($issue); |
|
47
|
|
|
if (isset($tmp->id)) { |
|
48
|
|
|
$issue->provider_id = $tmp->id; |
|
|
|
|
|
|
49
|
|
|
$issue->number = $tmp->number; |
|
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
$issue->provider = strtolower(Auth::user()->provider); |
|
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
// TODO Create a branch in GitHub |
|
55
|
|
|
//$model->branch->sync([['sprint_id' => true]]); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function created($issue) |
|
59
|
|
|
{ |
|
60
|
|
|
(new Status())->track('issue', $issue); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function updating($issue) |
|
64
|
|
|
{ |
|
65
|
|
|
if (isset($issue->number)) { |
|
66
|
|
|
app(Auth::user()->provider)->createOrUpdateIssue($issue); |
|
67
|
|
|
} |
|
68
|
|
|
(new Status())->track('issue', $issue); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function deleting(Issue $issue) |
|
72
|
|
|
{ |
|
73
|
|
|
$issue->comments()->delete(); |
|
74
|
|
|
$issue->attachments()->delete(); |
|
75
|
|
|
$issue->notes()->delete(); |
|
76
|
|
|
$issue->statuses()->delete(); |
|
77
|
|
|
$issue->favorite()->delete(); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
Since your code implements the magic setter
_set, this function will be called for any write access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.