Skip to content

Commit

Permalink
Merge pull request #57 from leepeuker/improve-cli-user-managment
Browse files Browse the repository at this point in the history
Update user managment commands and remove global movary command prefix
  • Loading branch information
leepeuker authored Jul 15, 2022
2 parents 67178f4 + ef1395d commit aa22482
Show file tree
Hide file tree
Showing 17 changed files with 212 additions and 189 deletions.
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,22 @@ db_migration_create:
app_sync_all: app_sync_trakt app_sync_tmdb

app_database_migrate:
make exec_app_cmd CMD="php bin/console.php movary:database:migration --migrate"
make exec_app_cmd CMD="php bin/console.php database:migration --migrate"

app_database_rollback:
make exec_app_cmd CMD="php bin/console.php movary:database:migration --rollback"
make exec_app_cmd CMD="php bin/console.php database:migration --rollback"

app_user_create_test:
make exec_app_cmd CMD="php bin/console.php movary:user:create a@a a"
make exec_app_cmd CMD="php bin/console.php user:create a@a a"

app_sync_trakt:
make exec_app_cmd CMD="php bin/console.php movary:sync-trakt --overwrite"
make exec_app_cmd CMD="php bin/console.php trakt:sync --overwrite --userId=1"

app_sync_tmdb:
make exec_app_cmd CMD="php bin/console.php movary:sync-tmdb"
make exec_app_cmd CMD="php bin/console.php tmdb:sync"

app_sync_letterboxd:
make exec_app_cmd CMD="php bin/console.php movary:sync-letterboxd $(CSV_PATH)"
make exec_app_cmd CMD="php bin/console.php letterboxd:sync $(CSV_PATH)"

# Tests
#######
Expand Down
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ volumes:
## Important: First steps
- Run database migrations: `docker exec movary php bin/console.php movary:database:migration --migrate`
- Create a user: `docker exec movary php bin/console.php movary:user:create [email protected] your-password`
- Run database migrations: `docker exec movary php bin/console.php database:migration --migrate`
- Create a user: `docker exec movary php bin/console.php user:create [email protected] your-password`

List all available cli commands: `docker exec movary php bin/console.php movary`
List all available cli commands: `docker exec movary php bin/console.php`

##### Available environment variables with defaults:

Expand Down Expand Up @@ -143,12 +143,11 @@ Add the generated url as a [webhook to plex](https://support.plex.tv/articles/11
You can sync your watch history and ratings from trakt.tv.
The user used in the sync process must have a trakt username and client id set (can be set via web UI on the settings page or via cli `movary:user:change-trakt-client-id`
and `movary:user:change-trakt-username`).
The user used in the sync process must have a trakt username and client id set (can be set via web UI on the settings page or via cli `user:update`).
Example (syncing history and ratings for user with id 1):
`docker exec movary php bin/console.php movary:sync-trakt --ratings --history --userId=1`
`docker exec movary php bin/console.php trakt:sync --ratings --history --userId=1`
**Flags:**
Expand All @@ -172,7 +171,7 @@ Make sure you have added the variables `TMDB_API_KEY` to the environment.
Example:
`docker exec movary php bin/console.php movary:sync-tmdb`
`docker exec movary php bin/console.php tmdb:sync`
**Flags:**
Expand Down
10 changes: 5 additions & 5 deletions bin/console.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
$application = $container->get(Symfony\Component\Console\Application::class);
$application->add($container->get(Movary\Command\SyncTrakt::class));
$application->add($container->get(Movary\Command\SyncTmdb::class));
$application->add($container->get(Movary\Command\SyncLetterboxd::class));
$application->add($container->get(Movary\Command\CreateUser::class));
$application->add($container->get(Movary\Command\ChangeUserPassword::class));
// $application->add($container->get(Movary\Command\SyncLetterboxd::class));
$application->add($container->get(Movary\Command\DatabaseMigration::class));
$application->add($container->get(Movary\Command\ChangeUserTraktClientId::class));
$application->add($container->get(Movary\Command\ChangeUserTraktUserName::class));
$application->add($container->get(Movary\Command\UserCreate::class));
$application->add($container->get(Movary\Command\UserDelete::class));
$application->add($container->get(Movary\Command\UserUpdate::class));
$application->add($container->get(Movary\Command\UserList::class));

$application->run();
10 changes: 10 additions & 0 deletions src/Application/User/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public function deleteUser(int $userId) : void
$this->repository->deleteUser($userId);
}

public function fetchAll() : array
{
return $this->repository->fetchAll();
}

public function fetchDateFormatId(int $userId) : int
{
$dateFormat = $this->repository->findDateFormatId($userId);
Expand Down Expand Up @@ -84,6 +89,11 @@ public function updateDateFormatId(int $userId, int $dateFormat) : void
$this->repository->updateDateFormatId($userId, $dateFormat);
}

public function updateEmail(int $userId, string $email) : void
{
$this->repository->updateEmail($userId, $email);
}

public function updatePassword(int $userId, string $newPassword) : void
{
if (strlen($newPassword) < self::PASSWORD_MIN_LENGTH) {
Expand Down
18 changes: 18 additions & 0 deletions src/Application/User/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public function deleteUser(int $userId) : void
$this->dbConnection->delete('user', ['id' => $userId]);
}

public function fetchAll() : array
{
return $this->dbConnection->fetchAllAssociative('SELECT * FROM `user`');
}

public function findAuthTokenExpirationDate(string $token) : ?DateTime
{
$expirationDate = $this->dbConnection->fetchOne('SELECT `expiration_date` FROM `user_auth_token` WHERE `token` = ?', [$token]);
Expand Down Expand Up @@ -175,6 +180,19 @@ public function updateDateFormatId(int $userId, int $dateFormat) : void
);
}

public function updateEmail(int $userId, string $email) : void
{
$this->dbConnection->update(
'user',
[
'email' => $email,
],
[
'id' => $userId,
]
);
}

public function updatePassword(int $userId, string $passwordHash) : void
{
$this->dbConnection->update(
Expand Down
54 changes: 0 additions & 54 deletions src/Command/ChangeUserPassword.php

This file was deleted.

53 changes: 0 additions & 53 deletions src/Command/ChangeUserTraktClientId.php

This file was deleted.

53 changes: 0 additions & 53 deletions src/Command/ChangeUserTraktUserName.php

This file was deleted.

2 changes: 0 additions & 2 deletions src/Command/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

abstract class Command extends \Symfony\Component\Console\Command\Command
{
protected const COMMAND_BASE_NAME = 'movary';

protected function generateOutput(OutputInterface $output, string $message) : void
{
$output->writeln(DateTime::create()->format('Y-m-d H:i:s:u') . ' - ' . $message);
Expand Down
2 changes: 1 addition & 1 deletion src/Command/DatabaseMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DatabaseMigration extends Command

private const OPTION_NAME_ROLLBACK = 'rollback';

protected static $defaultName = self::COMMAND_BASE_NAME . ':database:migration';
protected static $defaultName = 'database:migration';

public function __construct(
private readonly PhinxApplication $phinxApplication,
Expand Down
4 changes: 2 additions & 2 deletions src/Command/SyncLetterboxd.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

class SyncLetterboxd extends Command
{
protected static $defaultName = self::COMMAND_BASE_NAME . ':sync-letterboxd-ratings';

private const OPTION_NAME_OVERWRITE = 'overwrite';

protected static $defaultName = 'letterboxd:sync';

public function __construct(
private readonly SyncRatings $syncRatings,
private readonly LoggerInterface $logger,
Expand Down
2 changes: 1 addition & 1 deletion src/Command/SyncTmdb.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SyncTmdb extends Command

private const OPTION_NAME_FORCE_THRESHOLD = 'threshold';

protected static $defaultName = self::COMMAND_BASE_NAME . ':sync-tmdb';
protected static $defaultName = 'tmdb:sync';

public function __construct(
private readonly SyncMovies $syncMovieDetails,
Expand Down
2 changes: 1 addition & 1 deletion src/Command/SyncTrakt.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SyncTrakt extends Command

private const OPTION_NAME_USER_ID = 'userId';

protected static $defaultName = self::COMMAND_BASE_NAME . ':sync-trakt';
protected static $defaultName = 'trakt:sync';

public function __construct(
private readonly SyncRatings $syncRatings,
Expand Down
7 changes: 3 additions & 4 deletions src/Command/CreateUser.php → src/Command/UserCreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
namespace Movary\Command;

use Movary\Application\User\Api;
use Movary\Application\User\Service;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class CreateUser extends Command
class UserCreate extends Command
{
protected static $defaultName = self::COMMAND_BASE_NAME . ':user:create';
protected static $defaultName = 'user:create';

public function __construct(
private readonly Api $userApi,
Expand Down Expand Up @@ -46,7 +45,7 @@ protected function execute(InputInterface $input, OutputInterface $output) : int
return Command::FAILURE;
}

$this->generateOutput($output, 'Created user.');
$this->generateOutput($output, 'User created.');

return Command::SUCCESS;
}
Expand Down
Loading

0 comments on commit aa22482

Please sign in to comment.