Initial commit

This commit is contained in:
Chris Smith
2025-02-19 14:51:16 +01:00
commit d82a6cad96
198 changed files with 13819 additions and 0 deletions

3
console/config/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
main-local.php
params-local.php
test-local.php

View File

@@ -0,0 +1,2 @@
<?php
Yii::setAlias('@console', dirname(__DIR__));

58
console/config/main.php Normal file
View File

@@ -0,0 +1,58 @@
<?php
use yii\console\controllers\FixtureController;
use yii\console\controllers\MigrateController;
use yii\log\FileTarget;
use function Sentry\init;
$params = array_merge(
require __DIR__ . '/../../common/config/params.php',
require __DIR__ . '/../../common/config/params-local.php',
require __DIR__ . '/params.php',
require __DIR__ . '/params-local.php'
);
init([
'dsn' => $params['sentry.dsn'],
// Specify a fixed sample rate
'traces_sample_rate' => 1.0,
// Set a sampling rate for profiling - this is relative to traces_sample_rate
'profiles_sample_rate' => 1.0,
]);
return [
'id' => 'app-console',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log', 'queue'],
'controllerNamespace' => 'console\controllers',
'aliases' => [
'@bower' => '@vendor/bower-asset',
'@npm' => '@vendor/npm-asset',
],
'controllerMap' => [
'fixture' => [
'class' => FixtureController::class,
'namespace' => 'common\fixtures',
],
'migrate' => [
'class' => MigrateController::class,
'newFileOwnership' => '1000:1000', # Default WSL user id
'newFileMode' => 0660,
'migrationPath' => [
'@app/migrations',
'@yii/rbac/migrations',
],
],
],
'components' => [
'log' => [
'targets' => [
[
'class' => FileTarget::class,
'levels' => ['error', 'warning'],
],
],
]
],
'params' => $params,
];

View File

@@ -0,0 +1,5 @@
<?php
return [
'adminEmail' => 'admin@example.com',
];

4
console/config/test.php Normal file
View File

@@ -0,0 +1,4 @@
<?php
return [
];

View File

@@ -0,0 +1,96 @@
<?php
namespace console\controllers;
use yii\console\{Controller, ExitCode};
// To create/edit crontab file: crontab -e
// To list: crontab -l
// // m h dom mon dow command
// */5 * * * * /var/www/html/yii cron/frequent
// */15 * * * * /var/www/html/yii cron/quarter
// */30 * * * * /var/www/html/yii cron/halfhourly
// 0 * * * * /var/www/html/yii cron/hourly
// 15 1 * * * /var/www/html/yii cron/overnight
// 15 3 * * 5 /var/www/html/yii cron/weekly
/**
* Class CronController
*
* @package console\controllers
*/
class CronController extends Controller
{
/**
* @var boolean whether to run the command interactively.
*/
public $interactive = false;
/**
* Action Index
* @return int exit code
*/
public function actionIndex()
{
$this->stdout("Yes, service cron is running\n");
return ExitCode::OK;
}
/**
* Action Frequent
* Called every five minutes
* @return int exit code
*/
public function actionFrequent()
{
return ExitCode::OK;
}
/**
* Action Quarter
* Called every fifteen minutes
*
* @return int exit code
*/
public function actionQuarter()
{
//
return ExitCode::OK;
}
/**
* Action Half Hourly
* Called every 30 minutes
*
* @return int exit code
*/
public function actionHalfhourly()
{
return ExitCode::OK;
}
/**
* Action Hourly
* @return int exit code
*/
public function actionHourly()
{
return ExitCode::OK;
}
/**
* Action Overnight
* Called every night
*
* @return int exit code
*/
public function actionOvernight()
{
return ExitCode::OK;
}
}

View File

@@ -0,0 +1,45 @@
<?php
use common\models\User;
use yii\db\Migration;
/**
* Handles the creation of table `{{%user}}`.
*/
class m221203_160610_create_user_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$tableOptions = null;
if ($this->db->driverName === 'mysql') {
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
$tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB';
}
$this->createTable('{{%user}}', [
'id' => $this->primaryKey(),
'auth_key' => $this->string(32)->notNull(),
'password_hash' => $this->string()->notNull(),
'password_reset_token' => $this->string()->unique(),
'verification_token' => $this->string()->defaultValue(null),
'first_name' => $this->string(64),
'email' => $this->string()->notNull()->unique(),
'status' => $this->smallInteger()->notNull()->defaultValue(User::STATUS_UNVERIFIED),
'welcome_email_sent' => $this->boolean()->defaultValue(false),
'created_at' => $this->integer()->notNull(),
'updated_at' => $this->integer()->notNull(),
], $tableOptions);
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropTable('{{%user}}');
}
}

View File

@@ -0,0 +1,87 @@
<?php
use yii\db\Migration;
/**
* Class m230120_214209_init_rbac
*/
class m230120_214209_init_rbac extends Migration
{
public function up()
{
$auth = Yii::$app->authManager;
/**
* Permissions for future use?
* Maybe...
*/
// add "view meal" permission
$viewMeal = $auth->createPermission('viewMeal');
$viewMeal->description = 'View own meal records';
$auth->add($viewMeal);
// add "create meal" permission
$createMeal = $auth->createPermission('createMeal');
$createMeal->description = 'Create a new meal record';
$auth->add($createMeal);
// add "update meal" permission
$updateMeal = $auth->createPermission('updateMeal');
$updateMeal->description = 'Update own meal records';
$auth->add($updateMeal);
// add "delete meal" permission
$deleteMeal = $auth->createPermission('deleteMeal');
$deleteMeal->description = 'Delete own meal records';
$auth->add($deleteMeal);
// add "view all meals" permission (for admin)
$viewAllMeals = $auth->createPermission('viewAllMeals');
$viewAllMeals->description = 'View all meal records';
$auth->add($viewAllMeals);
// add "update all meals" permission (for admin)
$updateAllMeals = $auth->createPermission('updateAllMeals');
$updateAllMeals->description = 'Update any meal record';
$auth->add($updateAllMeals);
// add "delete all meals" permission (for admin)
$deleteAllMeals = $auth->createPermission('deleteAllMeals');
$deleteAllMeals->description = 'Delete any meal record';
$auth->add($deleteAllMeals);
// Add roles
$user = $auth->createRole('user');
$auth->add($user);
$admin = $auth->createRole('admin');
$auth->add($admin);
// Add permissions to roles (crucially important):
$auth->addChild($user, $viewMeal);
$auth->addChild($user, $createMeal);
$auth->addChild($user, $updateMeal);
$auth->addChild($user, $deleteMeal);
$auth->addChild($admin, $viewMeal);
$auth->addChild($admin, $createMeal);
$auth->addChild($admin, $updateMeal);
$auth->addChild($admin, $deleteMeal);
$auth->addChild($admin, $viewAllMeals);
$auth->addChild($admin, $updateAllMeals);
$auth->addChild($admin, $deleteAllMeals);
// Assign roles to users. 1 and 2 are IDs returned by IdentityInterface::getId()
// usually implemented in your User model.
$auth->assign($admin, 1);
}
public function down()
{
$auth = Yii::$app->authManager;
$auth->removeAll();
}
}

View File

@@ -0,0 +1,47 @@
<?php
use yii\db\Migration;
/**
* Class m230210_155341_queue_table
*/
class m230210_155341_queue_table extends Migration
{
public $tableName = '{{%queue}}';
/**
* {@inheritdoc}
*/
public function safeUp()
{
$tableOptions = null;
if ($this->db->driverName === 'mysql') {
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
$tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB';
}
$this->createTable($this->tableName, [
'id' => $this->primaryKey(),
'channel' => $this->string()->notNull(),
'job' => $this->binary()->notNull(),
'pushed_at' => $this->integer()->notNull(),
'ttr' => $this->integer()->notNull(),
'delay' => $this->integer()->notNull(),
'priority' => $this->integer()->unsigned()->notNull()->defaultValue(1024),
'reserved_at' => $this->integer(),
'attempt' => $this->integer(),
'done_at' => $this->integer(),
], $tableOptions);
$this->createIndex('channel', $this->tableName, 'channel');
$this->createIndex('reserved_at', $this->tableName, 'reserved_at');
$this->createIndex('priority', $this->tableName, 'priority');
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropTable($this->tableName);
}
}

View File

@@ -0,0 +1,36 @@
<?php
use yii\db\Migration;
/**
* Handles the creation of table `{{%meal}}`.
*/
class m250219_133939_create_meal_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->createTable('{{%meal}}', [
'id' => $this->primaryKey(),
'file_name' => $this->string()->notNull(),
'calories' => $this->integer()->notNull(),
'protein' => $this->integer()->notNull(),
'fat' => $this->integer()->notNull(),
'carbohydrates' => $this->integer()->notNull(),
'fiber' => $this->integer()->notNull(),
'meal' => $this->integer()->notNull(),
'created_at' => $this->integer()->notNull(),
'updated_at' => $this->integer()->notNull(),
]);
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropTable('{{%meal}}');
}
}

1
console/models/.gitkeep Normal file
View File

@@ -0,0 +1 @@
*

2
console/runtime/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
*
!.gitignore