Skip to content

Commit a137e6e

Browse files
committed
Add base implementation of extendable events classes
Modified server deletion to use internal event handlers from the Eloquent models themselves. Also added a few preliminary event handlers in the `Pterodactyl\Events\<USer|Server> namespace that users can hook into in EventServiceProvider to perform their own actions as they please (such as push notifications and such).
1 parent bf7b584 commit a137e6e

File tree

16 files changed

+505
-41
lines changed

16 files changed

+505
-41
lines changed
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222
* SOFTWARE.
2323
*/
2424

25-
namespace Pterodactyl\Events;
25+
namespace Pterodactyl\Events\Server;
2626

27+
use Pterodactyl\Models\Server;
2728
use Illuminate\Queue\SerializesModels;
2829

29-
class ServerDeleted
30+
class Created
3031
{
3132
use SerializesModels;
3233

@@ -37,8 +38,8 @@ class ServerDeleted
3738
*
3839
* @return void
3940
*/
40-
public function __construct($id)
41+
public function __construct(Server $server)
4142
{
42-
$this->server = $id;
43+
$this->server = $server;
4344
}
4445
}
Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,41 +22,24 @@
2222
* SOFTWARE.
2323
*/
2424

25-
namespace Pterodactyl\Listeners;
25+
namespace Pterodactyl\Events\Server;
2626

27-
use Carbon;
28-
use Pterodactyl\Jobs\DeleteServer;
29-
use Pterodactyl\Jobs\SuspendServer;
30-
use Pterodactyl\Events\ServerDeleted;
31-
use Illuminate\Foundation\Bus\DispatchesJobs;
27+
use Pterodactyl\Models\Server;
28+
use Illuminate\Queue\SerializesModels;
3229

33-
class DeleteServerListener
30+
class Creating
3431
{
35-
use DispatchesJobs;
32+
use SerializesModels;
3633

37-
/**
38-
* Create the event listener.
39-
*
40-
* @return void
41-
*/
42-
public function __construct()
43-
{
44-
//
45-
}
34+
public $server;
4635

4736
/**
48-
* Handle the event.
37+
* Create a new event instance.
4938
*
50-
* @param DeleteServerEvent $event
5139
* @return void
5240
*/
53-
public function handle(ServerDeleted $event)
41+
public function __construct(Server $server)
5442
{
55-
$this->dispatch((new SuspendServer($event->server))->onQueue(env('QUEUE_HIGH', 'high')));
56-
$this->dispatch(
57-
(new DeleteServer($event->server))
58-
->delay(Carbon::now()->addMinutes(env('APP_DELETE_MINUTES', 10)))
59-
->onQueue(env('QUEUE_STANDARD', 'standard'))
60-
);
43+
$this->server = $server;
6144
}
6245
}

app/Events/Server/Deleted.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace Pterodactyl\Events\Server;
26+
27+
use Pterodactyl\Models\Server;
28+
use Illuminate\Queue\SerializesModels;
29+
30+
class Deleted
31+
{
32+
use SerializesModels;
33+
34+
public $server;
35+
36+
/**
37+
* Create a new event instance.
38+
*
39+
* @return void
40+
*/
41+
public function __construct(Server $server)
42+
{
43+
$this->server = $server;
44+
}
45+
}

app/Events/Server/Deleting.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace Pterodactyl\Events\Server;
26+
27+
use Pterodactyl\Models\Server;
28+
use Illuminate\Queue\SerializesModels;
29+
30+
class Deleting
31+
{
32+
use SerializesModels;
33+
34+
public $server;
35+
36+
/**
37+
* Create a new event instance.
38+
*
39+
* @return void
40+
*/
41+
public function __construct(Server $server)
42+
{
43+
$this->server = $server;
44+
}
45+
}

app/Events/User/Created.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace Pterodactyl\Events\User;
26+
27+
use Pterodactyl\Models\User;
28+
use Illuminate\Queue\SerializesModels;
29+
30+
class Created
31+
{
32+
use SerializesModels;
33+
34+
public $user;
35+
36+
/**
37+
* Create a new event instance.
38+
*
39+
* @return void
40+
*/
41+
public function __construct(User $user)
42+
{
43+
$this->user = $user;
44+
}
45+
}

app/Events/User/Creating.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace Pterodactyl\Events\User;
26+
27+
use Pterodactyl\Models\User;
28+
use Illuminate\Queue\SerializesModels;
29+
30+
class Creating
31+
{
32+
use SerializesModels;
33+
34+
public $user;
35+
36+
/**
37+
* Create a new event instance.
38+
*
39+
* @return void
40+
*/
41+
public function __construct(User $user)
42+
{
43+
$this->user = $user;
44+
}
45+
}

app/Events/User/Deleted.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace Pterodactyl\Events\User;
26+
27+
use Pterodactyl\Models\User;
28+
use Illuminate\Queue\SerializesModels;
29+
30+
class Deleted
31+
{
32+
use SerializesModels;
33+
34+
public $user;
35+
36+
/**
37+
* Create a new event instance.
38+
*
39+
* @return void
40+
*/
41+
public function __construct(User $user)
42+
{
43+
$this->user = $user;
44+
}
45+
}

app/Events/User/Deleting.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace Pterodactyl\Events\User;
26+
27+
use Pterodactyl\Models\User;
28+
use Illuminate\Queue\SerializesModels;
29+
30+
class Deleting
31+
{
32+
use SerializesModels;
33+
34+
public $user;
35+
36+
/**
37+
* Create a new event instance.
38+
*
39+
* @return void
40+
*/
41+
public function __construct(User $user)
42+
{
43+
$this->user = $user;
44+
}
45+
}

app/Models/Node.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@
2626

2727
use GuzzleHttp\Client;
2828
use Illuminate\Database\Eloquent\Model;
29+
use Illuminate\Notifications\Notifiable;
2930

3031
class Node extends Model
3132
{
33+
use Notifiable;
34+
3235
/**
3336
* The table associated with the model.
3437
*

app/Models/Server.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@
2626

2727
use Auth;
2828
use Illuminate\Database\Eloquent\Model;
29+
use Illuminate\Notifications\Notifiable;
2930
use Illuminate\Database\Eloquent\SoftDeletes;
3031

3132
class Server extends Model
3233
{
33-
use SoftDeletes;
34+
use Notifiable, SoftDeletes;
3435

3536
/**
3637
* The table associated with the model.

0 commit comments

Comments
 (0)