Skip to content
This repository was archived by the owner on Feb 2, 2018. It is now read-only.

Commit 593986b

Browse files
committed
Merge pull request #60 from GroupEat/develop
Release 1.0.0
2 parents 3d3ed6e + 966fa7c commit 593986b

File tree

284 files changed

+6566
-4181
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

284 files changed

+6566
-4181
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.DS_Store
33
Thumbs.db
44
.env
5-
APNS.pem
5+
.apns.pem
66
.phpstorm.meta.php
77
_ide_helper.php
88
_ide_helper_models.php

.rocketeer/events.php

+17-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,22 @@
33
use Rocketeer\Facades\Rocketeer;
44

55
Rocketeer::listenTo('deploy.before-symlink', function ($task) {
6-
$path = $task->releasesManager->getCurrentReleasePath();
6+
$commands = [
7+
'optimize',
8+
'api:cache',
9+
'config:cache',
10+
'opcache:clear',
11+
'docs',
12+
'adminer',
13+
'db:backup --s3',
14+
];
715

8-
foreach (['optimize', 'route:cache', 'config:cache', 'opcache:clear', 'docs', 'adminer'] as $command) {
9-
$task->run("cd $path; php artisan $command");
10-
}
16+
array_map(function ($command) use ($task) {
17+
$task->runForCurrentRelease("php artisan $command");
18+
19+
if (!$task->status()) {
20+
$task->explainer->error("Cancelling release because command '$command' failed");
21+
exit(1);
22+
}
23+
}, $commands);
1124
});

.rocketeer/hooks.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,16 @@
2727
function ($task) {
2828
$sharedFolder = $task->paths->getFolder('shared');
2929

30-
foreach (['.env', 'APNS.pem'] as $file) {
30+
foreach (['.env', '.apns.pem'] as $file) {
3131
$task->run("ln -s ~vagrant/$file $sharedFolder/$file");
3232
}
3333
},
3434
],
35-
'deploy' => [],
35+
'deploy' => [
36+
function ($task) {
37+
$task->runForCurrentRelease('php artisan migrate --force');
38+
}
39+
],
3640
'cleanup' => [],
3741
],
3842

.rocketeer/remote.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
// user uploaded data, file-based databases, etc.
3232
'shared' => [
3333
'.env',
34-
'APNS.pem',
34+
'.apns.pem',
3535
'storage/logs',
3636
],
3737

@@ -61,7 +61,6 @@
6161
// permissions on the folder above. The Closure can return
6262
// a single command as a string or an array of commands
6363
'callback' => function ($task, $file) {
64-
var_dump($file);
6564
return [
6665
sprintf('chmod -R 775 %s', $file),
6766
sprintf('chmod -R g+s %s', $file),

app/Admin/Console/Adminer.php

+45-7
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,63 @@
11
<?php
22
namespace Groupeat\Admin\Console;
33

4-
use Groupeat\Admin\Services\GenerateAdminerFiles;
54
use Groupeat\Support\Console\Abstracts\Command;
5+
use GuzzleHttp\Client;
6+
use Illuminate\Contracts\Filesystem\Filesystem;
67

78
class Adminer extends Command
89
{
9-
protected $name = 'adminer';
10+
const THEME = 'pappu687';
11+
const RED = '#ff4e50';
12+
const GREEN = '#23AF50';
13+
14+
protected $signature = 'adminer';
1015
protected $description = "Generate the Adminer files to manage the DB";
1116

12-
private $generateAdminerFiles;
17+
private $client;
18+
private $filesystem;
1319

14-
public function __construct(GenerateAdminerFiles $generateAdminerFiles)
20+
public function __construct(Filesystem $filesystem)
1521
{
1622
parent::__construct();
1723

18-
$this->generateAdminerFiles = $generateAdminerFiles;
24+
$this->client = new Client;
25+
$this->filesystem = $filesystem;
1926
}
2027

21-
public function fire()
28+
public function handle()
2229
{
23-
$this->generateAdminerFiles->call($this->getOutput());
30+
$this->line("Listing available versions");
31+
32+
$response = $this->client->get('https://api.github.com/repos/vrana/adminer/tags');
33+
34+
$latestVersion = collect(json_decode($response->getBody(), true))
35+
->map(function ($tag) {
36+
return trim($tag['name'], 'v');
37+
})
38+
->sortByDesc(null)
39+
->first();
40+
41+
$this->line("Latest version found: $latestVersion");
42+
$this->line("Downloading PHP file");
43+
44+
$this->client->get("http://downloads.sourceforge.net/adminer/adminer-$latestVersion-en.php", [
45+
'save_to' => storage_path('app/adminer.php'),
46+
]);
47+
48+
$this->line("Downloading CSS file");
49+
50+
$css = (string) $this->client
51+
->get('https://raw.github.com/vrana/adminer/master/designs/' . static::THEME . '/adminer.css')
52+
->getBody();
53+
54+
$this->line("Applying GroupEat theme");
55+
56+
$css = str_replace('#34495e', static::RED, $css);
57+
$css = str_replace(['#48A5BF', '#65ADC3', 'rgb(85, 112, 139)', '#2980b9'], static::GREEN, $css);
58+
59+
$this->line("Saving CSS file");
60+
61+
$this->filesystem->put('adminer.css', $css);
2462
}
2563
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
namespace Groupeat\Admin\Console;
3+
4+
use Carbon\Carbon;
5+
use Groupeat\Admin\Events\GroupOrderHasNotBeenConfirmed;
6+
use Groupeat\Admin\Values\MaxConfirmationDurationInMinutes;
7+
use Groupeat\Orders\Entities\GroupOrder;
8+
use Groupeat\Support\Console\Abstracts\Command;
9+
use Illuminate\Contracts\Events\Dispatcher;
10+
11+
class DetectUncomfirmedGroupOrders extends Command
12+
{
13+
protected $signature = 'group-orders:detect-uncomfirmed';
14+
protected $description = "Detect group orders that should have been confirmed and fire events if found";
15+
16+
private $events;
17+
private $maxConfirmationDurationInMinutes;
18+
19+
public function __construct(
20+
Dispatcher $events,
21+
MaxConfirmationDurationInMinutes $maxConfirmationDurationInMinutes
22+
) {
23+
parent::__construct();
24+
25+
$this->events = $events;
26+
$this->maxConfirmationDurationInMinutes = $maxConfirmationDurationInMinutes;
27+
}
28+
29+
public function handle()
30+
{
31+
GroupOrder::unconfirmed($this->maxConfirmationDurationInMinutes)
32+
->get()
33+
->each(function (GroupOrder $groupOrder) {
34+
$this->comment($groupOrder->toShortString() . ' is unconfirmed');
35+
$this->events->fire(new GroupOrderHasNotBeenConfirmed($groupOrder));
36+
});
37+
}
38+
}

app/Admin/Entities/Admin.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Admin extends Entity implements User
1010
{
1111
use HasCredentials, SoftDeletes;
1212

13-
protected $dates = ['deletedAt'];
13+
protected $dates = [self::DELETED_AT];
1414

1515
public function getRules()
1616
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
namespace Groupeat\Admin\Events;
3+
4+
use Groupeat\Orders\Entities\GroupOrder;
5+
use Groupeat\Support\Events\Abstracts\Event;
6+
7+
class GroupOrderHasNotBeenConfirmed extends Event
8+
{
9+
private $groupOrder;
10+
11+
public function __construct(GroupOrder $groupOrder)
12+
{
13+
$this->groupOrder = $groupOrder;
14+
}
15+
16+
public function getGroupOrder()
17+
{
18+
return $this->groupOrder;
19+
}
20+
21+
public function __toString()
22+
{
23+
$groupOrderPresenter = $this->groupOrder->getPresenter();
24+
$restaurant = $this->groupOrder->restaurant;
25+
26+
return 'The ' . $this->groupOrder->toShortString()
27+
. ' has been closed at ' . $groupOrderPresenter->closedAtTime
28+
. ' but has not been confirmed yet by ' . $restaurant->toShortString()
29+
. ' (' . $restaurant->phoneNumber . ').';
30+
}
31+
}

app/Admin/Migrations/AdminsMigration.php

-23
This file was deleted.

app/Admin/PackageProvider.php

+10
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,23 @@
22
namespace Groupeat\Admin;
33

44
use Groupeat\Admin\Entities\Admin;
5+
use Groupeat\Admin\Services\ShareNoteworthyEventsOnSlack;
6+
use Groupeat\Admin\Values\MaxConfirmationDurationInMinutes;
57
use Groupeat\Auth\Auth;
68
use Groupeat\Support\Providers\Abstracts\WorkbenchPackageProvider;
79

810
class PackageProvider extends WorkbenchPackageProvider
911
{
12+
protected $configValues = [
13+
MaxConfirmationDurationInMinutes::class => 'admin.max_confirmation_duration_in_minutes',
14+
];
15+
1016
protected function bootPackage()
1117
{
1218
$this->app[Auth::class]->addUserType(new Admin);
19+
20+
foreach (ShareNoteworthyEventsOnSlack::EVENT_CLASSES as $eventClass) {
21+
$this->listen($eventClass, ShareNoteworthyEventsOnSlack::class, 'share');
22+
}
1323
}
1424
}

app/Admin/Services/GenerateAdminerFiles.php

-54
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
namespace Groupeat\Admin\Services;
3+
4+
use Groupeat\Admin\Events\GroupOrderHasNotBeenConfirmed;
5+
use Groupeat\Auth\Events\UserHasRegistered;
6+
use Groupeat\Orders\Events\GroupOrderHasBeenCreated;
7+
use Groupeat\Orders\Events\GroupOrderHasBeenJoined;
8+
use Groupeat\Support\Events\Abstracts\Event;
9+
use Groupeat\Support\Listeners\Abstracts\QueuedListener;
10+
use Groupeat\Support\Values\Environment;
11+
use GuzzleHttp\Client;
12+
use GuzzleHttp\Exception\ClientException;
13+
use Psr\Log\LoggerInterface;
14+
use Symfony\Component\HttpFoundation\Response;
15+
16+
class ShareNoteworthyEventsOnSlack extends QueuedListener
17+
{
18+
const URL = 'https://hooks.slack.com/services/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';
19+
20+
const EVENT_CLASSES = [
21+
UserHasRegistered::class,
22+
GroupOrderHasBeenCreated::class,
23+
GroupOrderHasBeenJoined::class,
24+
GroupOrderHasNotBeenConfirmed::class,
25+
];
26+
27+
private $client;
28+
private $environment;
29+
private $logger;
30+
31+
public function __construct(Environment $environment, LoggerInterface $logger)
32+
{
33+
$this->client = new Client;
34+
$this->environment = $environment;
35+
$this->logger = $logger;
36+
}
37+
38+
public function share($event)
39+
{
40+
foreach (static::EVENT_CLASSES as $eventClass) {
41+
if ($event instanceof $eventClass) {
42+
if ($this->environment->isProduction()) {
43+
$json = ['text' => (string) $event];
44+
45+
try {
46+
$response = $this->client->post(static::URL, compact('json'));
47+
} catch (ClientException $e) {
48+
$this->logger->error("Could not share event [$event] on Slack.");
49+
}
50+
} else {
51+
$this->logger->debug("Event [$event] would have been shared on Slack.");
52+
}
53+
}
54+
}
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
namespace Groupeat\Admin\Values;
3+
4+
use Groupeat\Support\Values\Abstracts\Value;
5+
6+
class MaxConfirmationDurationInMinutes extends Value
7+
{
8+
//
9+
}

0 commit comments

Comments
 (0)