Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions .docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
version: '3.5'
services:

sqldb:
image: mysql:5.7
environment:
- MYSQL_DATABASE=arcv
- MYSQL_DATABASE=arcv_service
- MYSQL_USER=arcvuser
- MYSQL_PASSWORD=arcvpassword
- MYSQL_ROOT_PASSWORD=changemeplease
volumes:
- ./initdb.d:/docker-entrypoint-initdb.d
- mysql-data:/var/lib/mysql
command: --default-storage-engine innodb
restart: unless-stopped
ports:
- 3336:3306
healthcheck:
test: mysqladmin -p$$MYSQL_ROOT_PASSWORD ping -h localhost
interval: 20s
Expand All @@ -24,6 +28,8 @@ services:
volumes:
- ./nginx_default.conf:/etc/nginx/conf.d/default.conf
- ../:/opt/project:ro
restart: unless-stopped
depends_on: [service]

service:
image: arc-service:dev
Expand All @@ -37,7 +43,7 @@ services:
- DB_CONNECTION=mysql
- DB_HOST=sqldb
- DB_PORT=3306
- DB_DATABASE=arcv
- DB_DATABASE=arcv_service
- DB_USERNAME=arcvuser
- DB_PASSWORD=arcvpassword
- LOG_CHANNEL=stderr
Expand All @@ -52,11 +58,21 @@ services:
- "arcv-service.test:host-gateway"
- "arcv-store.test:host-gateway"
- "arcv-market.test:host-gateway"
restart: unless-stopped
depends_on: [sqldb]

mailer:
image: schickling/mailcatcher
ports:
- "${MAILER_ADMIN_PORT:-2080}:1080"
restart: unless-stopped

volumes:
service_public:
service_public:
mysql-data:

# docker compose -f .docker/docker-compose.yml up -d
# docker compose -f .docker/docker-compose.yml logs -f
# docker compose -f .docker/docker-compose.yml exec service bash
# docker compose -f .docker/docker-compose.yml exec service /opt/project/artisan
# docker compose -f .docker/docker-compose.yml exec sqldb mysql -uarcvuser -parcvpassword arcv_service
56 changes: 56 additions & 0 deletions app/Console/Commands/ArcSkunk.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace App\Console\Commands;

use App\Centre;
use App\Family;
use App\Voucher;
use Illuminate\Console\Command;
use Symfony\Component\Console\Command\Command as CommandAlias;

// docker compose -f .docker/docker-compose.yml exec service /opt/project/artisan arc:skunk
class ArcSkunk extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'arc:skunk';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';

/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
$this->findVoucher();
return CommandAlias::SUCCESS;
}

public function findVoucher()
{
for ($i = 1109247; $i < 1109326; $i++) {
$v =Voucher::where("code", "SK" . $i)->first();
if (!$v) {
$this->warn("Voucher SK" . $i . " not found");
continue;
}
if ($v->reimbursedOn) {
$this->info("Voucher SK" . $i . " Reimbursed on " . $v->reimbursedOn->updated_at);
} else if ($v->paymentPendedOn) {
$this->info("Voucher SK" . $i . " Payment pending");
} else {
$this->info("Voucher SK" . $i . " still live");
}
}
}
}
94 changes: 94 additions & 0 deletions app/Console/Commands/MoveFamilies.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

namespace App\Console\Commands;

use App\Centre;
use App\Family;
use App\Registration;
use App\Voucher;
use Illuminate\Console\Command;
use Symfony\Component\Console\Command\Command as CommandAlias;

// docker compose -f .docker/docker-compose.yml exec service /opt/project/artisan arc:skunk
class MoveFamilies extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'arc:move:families {from_centre} {to_centre} {family_ids} ';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Move families between centres, e.g. ./artisan arc:move:families 101 113 4,42,44,46,39,40,41,45';

/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
$this->fixFamalams();
return CommandAlias::SUCCESS;
}

public function fixFamalams()
{
// TODO: If we get another request like this we should abstract this to a command that takes these as args
$from_centre_id = $this->argument('from_centre'); // 101;
$to_centre_id = $this->argument('to_centre'); // 113;
$family_list = explode(",", $this->argument('family_ids'));

$this->info(sprintf("Moving families %s for centre %d to %d", implode(",", $family_list), $from_centre_id, $to_centre_id));

$from_centre = Centre::where("id", $from_centre_id)->first();
$to_centre = Centre::find($to_centre_id);
$this->info(sprintf("From centre: %s, to centre: %s", $from_centre->name, $to_centre->name));

$reg_associated_with_fam = $from_centre
->registrations()
->withFullFamily()
->get()
->filter(function ($f) use ($family_list) {
return in_array($f->family->centre_sequence, $family_list);
});
if (count($reg_associated_with_fam) == 0) {
$this->warn("No matching registrations found");
}

foreach ($reg_associated_with_fam as $singleReg) {
/* @var Registration $singleReg */
$this->info(sprintf(
"Registration: id='%s', family id=%s, centre id=%s, bundle count=%d",
$singleReg->id,
$singleReg->family->id,
$singleReg->centre->id,
count($singleReg->bundles),
));
$bundles = $singleReg->bundles;
// "change disbursing_centre_id to new centre id where it is not null";
foreach ($bundles as $bundle) {
$this->info(sprintf(
" Bundle: id=%s, distributing centre id=%s",
$bundle->id,
$bundle->disbursing_centre_id,
));
if ($bundle->disbursing_centre_id != null && $bundle->disbursing_centre_id != $from_centre_id) {
$bundle->disbursing_centre_id = $to_centre_id;
// $this->info(sprintf(" Updating bundle->disbursing_centre_id = %s", $to_centre_id));
$bundle->save();
}
}
$this->info(sprintf(" Locking family %s to centre %s", $singleReg->family->id, $to_centre->id));
$singleReg->family->lockToCentre($to_centre, true);
$singleReg->family->save();
$singleReg->centre_id = $to_centre->id;
$singleReg->save();
}
}
}
69 changes: 69 additions & 0 deletions app/Console/Commands/UnbundleVouchers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace App\Console\Commands;

use App\Bundle;
use App\Voucher;
use Illuminate\Console\Command;
use Symfony\Component\Console\Command\Command as CommandAlias;

// docker compose -f .docker/docker-compose.yml exec service /opt/project/artisan arc:skunk
class UnbundleVouchers extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'arc:unbundle {prefix} {start_id} {end_id} ';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Remove vouchers from a bundle, e.g. ./artisan arc:unbundle SK 1109247 1109326';

/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
// grab vouchers
$vouchers = [];
for ($i = $this->argument('start_id'); $i <= (intval($this->argument('end_id'))); $i++) {
$vouchers[] = Voucher::where('code', $this->argument('prefix') . $i)->first();
}

// get bundle ids
$bundle_ids = [];
foreach ($vouchers as $v) {
$bundle_ids[] = $v->bundle_id;
}
$bundle_ids = array_unique($bundle_ids);

// warn that we will destroy these bundles, other vouchers in the bundle will be unbundled
$this->warn(sprintf("This will destroy the bundles with the IDs %s", implode(", ", $bundle_ids)));
if (!$this->confirm('Are you sure you want to proceed?')) {
// Code to execute if the user confirms
$this->info('Run back home then little petal...');
}

// foreach voucher, null the bundle id
foreach ($vouchers as $v) {
$v->bundle_id = null;
$this->info('Nulling bundle on ' . $v->code);
$v->save();
}

// foreach bundle delete the bundle
foreach ($bundle_ids as $bundle_id) {
$b = Bundle::where('id', $bundle_id);
$this->info('Deleting bundle ' . $bundle_id);
$b->delete();
}
return CommandAlias::SUCCESS;
}
}
Loading