Skip to content

Commit 35560af

Browse files
Merge pull request #4 from AidynMakhataev/dev
Dev
2 parents 3309deb + a841914 commit 35560af

File tree

4 files changed

+96
-0
lines changed

4 files changed

+96
-0
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,28 @@ TARANTOOL_SESSION_PASSWORD=password
4646
TARANTOOL_SESSION_SPACE=sessions
4747
```
4848

49+
## Transfer session from another storage
50+
51+
You can easily transfer your sessions with following artisan commands
52+
53+
### File Driver
54+
55+
```bash
56+
php artisan tarantool-session:transfer-file
57+
```
58+
59+
### Redis Driver
60+
61+
Currently not supported
62+
63+
### Database Driver
64+
65+
Currently not supported
66+
67+
### Memcached Driver
68+
69+
Currently not supported
70+
4971
## License
5072

5173
MIT. Please see the [license file](LICENSE) for more information.

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"require": {
1313
"php": "^7.2",
1414
"tarantool/client": "^0.8.0",
15+
"illuminate/console": "^5.5 || ^6 || ^7",
1516
"illuminate/session": "~5.0|~6.0|~7.0",
1617
"rybakit/msgpack": "^0.7.0"
1718
},
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace AidynMakhataev\Tarantool\Session\Console;
6+
7+
use AidynMakhataev\Tarantool\Session\TarantoolSessionHandler;
8+
use Illuminate\Console\Command;
9+
10+
/**
11+
* Class TransferSessionFromFileCommand.
12+
*/
13+
final class TransferSessionFromFileCommand extends Command
14+
{
15+
/**
16+
* The name and signature of the console command.
17+
*
18+
* @var string
19+
*/
20+
protected $signature = 'tarantool-session:transfer-file';
21+
22+
/**
23+
* The console command description.
24+
*
25+
* @var string
26+
*/
27+
protected $description = 'Transfer session from file storage to tarantool';
28+
29+
/** @var TarantoolSessionHandler */
30+
private $sessionHandler;
31+
32+
private static $ignoreFileList = [
33+
'.gitignore',
34+
];
35+
36+
/**
37+
* Create a new command instance.
38+
*
39+
* @param TarantoolSessionHandler $handler
40+
*/
41+
public function __construct(TarantoolSessionHandler $handler)
42+
{
43+
$this->sessionHandler = $handler;
44+
parent::__construct();
45+
}
46+
47+
/**
48+
* Execute the console command.
49+
*
50+
* @return void
51+
*/
52+
public function handle(): void
53+
{
54+
$directory = new \DirectoryIterator(storage_path('framework/sessions'));
55+
56+
foreach ($directory as $file) {
57+
if ($file->isFile() && ! in_array($file->getFilename(), self::$ignoreFileList)) {
58+
$key = $file->getFilename();
59+
60+
$value = file_get_contents($file->getPathname());
61+
62+
$this->sessionHandler->write($key, $value);
63+
}
64+
}
65+
66+
$this->info('Transfer successfully completed');
67+
}
68+
}

src/SessionServiceProvider.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace AidynMakhataev\Tarantool\Session;
66

7+
use AidynMakhataev\Tarantool\Session\Console\TransferSessionFromFileCommand;
78
use Illuminate\Contracts\Foundation\Application;
89
use Illuminate\Support\Facades\Session;
910
use Illuminate\Support\ServiceProvider;
@@ -19,6 +20,10 @@ public function register(): void
1920
$this->mergeConfigFrom(
2021
__DIR__.'/../config/tarantool-session.php', 'tarantool-session'
2122
);
23+
24+
$this->commands([
25+
TransferSessionFromFileCommand::class,
26+
]);
2227
}
2328

2429
public function boot(): void

0 commit comments

Comments
 (0)