|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Canvas\Cli\Tasks; |
|
4
|
|
|
|
|
5
|
|
|
use function Canvas\Core\appPath; |
|
6
|
|
|
use Phalcon\Cache\Backend\Libmemcached; |
|
|
|
|
|
|
7
|
|
|
use Phalcon\Cli\Task as PhTask; |
|
|
|
|
|
|
8
|
|
|
use RecursiveDirectoryIterator; |
|
9
|
|
|
use RecursiveIteratorIterator; |
|
10
|
|
|
use Phalcon\Queue\Beanstalk\Extended as BeanstalkExtended; |
|
11
|
|
|
use Phalcon\Queue\Beanstalk\Job; |
|
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Class ClearcacheTask. |
|
15
|
|
|
* |
|
16
|
|
|
* @package Canvas\Cli\Tasks |
|
17
|
|
|
* |
|
18
|
|
|
* @property Libmemcached $cache |
|
19
|
|
|
* @property Config $config |
|
20
|
|
|
*/ |
|
21
|
|
|
class ClearcacheTask extends PhTask |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Clears the data cache from the application. |
|
25
|
|
|
*/ |
|
26
|
1 |
|
public function mainAction() |
|
27
|
|
|
{ |
|
28
|
1 |
|
$this->clearFileCache(); |
|
29
|
1 |
|
$this->clearMemCached(); |
|
30
|
1 |
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Clears file based cache. |
|
34
|
|
|
*/ |
|
35
|
1 |
|
protected function clearFileCache() : void |
|
36
|
|
|
{ |
|
37
|
1 |
|
echo 'Clearing Cache folders' . PHP_EOL; |
|
38
|
|
|
|
|
39
|
1 |
|
$fileList = []; |
|
40
|
1 |
|
$whitelist = ['.', '..', '.gitignore']; |
|
41
|
1 |
|
$path = appPath('storage/cache'); |
|
42
|
1 |
|
$dirIterator = new RecursiveDirectoryIterator($path); |
|
43
|
1 |
|
$iterator = new RecursiveIteratorIterator( |
|
44
|
1 |
|
$dirIterator, |
|
45
|
1 |
|
RecursiveIteratorIterator::CHILD_FIRST |
|
46
|
|
|
); |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Get how many files we have there and where they are. |
|
50
|
|
|
*/ |
|
51
|
1 |
|
foreach ($iterator as $file) { |
|
52
|
1 |
|
if (true !== $file->isDir() && true !== in_array($file->getFilename(), $whitelist)) { |
|
53
|
1 |
|
$fileList[] = $file->getPathname(); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
1 |
|
echo sprintf('Found %s files', count($fileList)) . PHP_EOL; |
|
58
|
1 |
|
foreach ($fileList as $file) { |
|
59
|
1 |
|
echo '.'; |
|
60
|
1 |
|
unlink($file); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
1 |
|
echo PHP_EOL . 'Cleared Cache folders' . PHP_EOL; |
|
64
|
1 |
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Clears memcached data cache. |
|
68
|
|
|
*/ |
|
69
|
1 |
|
protected function clearMemCached() : void |
|
70
|
|
|
{ |
|
71
|
1 |
|
echo 'Clearing data cache' . PHP_EOL; |
|
72
|
1 |
|
$options = $this->cache->getOptions(); |
|
73
|
1 |
|
$servers = $options['servers'] ?? []; |
|
74
|
1 |
|
$memcached = new \Memcached(); |
|
75
|
1 |
|
foreach ($servers as $server) { |
|
76
|
1 |
|
$memcached->addServer($server['host'], $server['port'], $server['weight']); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
1 |
|
$keys = $memcached->getAllKeys(); |
|
80
|
|
|
//print_r($keys); |
|
81
|
1 |
|
echo sprintf('Found %s keys', count($keys)) . PHP_EOL; |
|
82
|
1 |
|
foreach ($keys as $key) { |
|
83
|
|
|
if ('bakaapi-' === substr($key, 0, 8)) { |
|
84
|
|
|
$server = $memcached->getServerByKey($key); |
|
85
|
|
|
$result = $memcached->deleteByKey($server['host'], $key); |
|
86
|
|
|
$resultCode = $memcached->getResultCode(); |
|
87
|
|
|
if (true === $result && $resultCode !== \Memcached::RES_NOTFOUND) { |
|
88
|
|
|
echo '.'; |
|
89
|
|
|
} else { |
|
90
|
|
|
echo 'F'; |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
1 |
|
echo PHP_EOL . 'Cleared data cache' . PHP_EOL; |
|
96
|
1 |
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Clean user session. |
|
100
|
|
|
* |
|
101
|
|
|
* @return void |
|
102
|
|
|
*/ |
|
103
|
|
|
public function sessionsAction() : void |
|
104
|
|
|
{ |
|
105
|
|
|
//call queue |
|
106
|
|
|
$queue = new BeanstalkExtended([ |
|
107
|
|
|
'host' => $this->config->beanstalk->host, |
|
108
|
|
|
'prefix' => $this->config->beanstalk->prefix, |
|
109
|
|
|
]); |
|
110
|
|
|
|
|
111
|
|
|
//call que que tube |
|
112
|
|
|
$queue->addWorker(getenv('SESSION_QUEUE'), function (Job $job) { |
|
113
|
|
|
// Here we should collect the meta information, make the screenshots, convert the video to the FLV etc. |
|
114
|
|
|
|
|
115
|
|
|
$sessionId = $job->getBody(); |
|
116
|
|
|
echo "\nProccessing: {$sessionId}\n"; |
|
117
|
|
|
|
|
118
|
|
|
$session = new \Baka\Auth\Models\Sessions(); |
|
119
|
|
|
$session->clean($sessionId, true); |
|
120
|
|
|
|
|
121
|
|
|
// It's very important to send the right exit code! |
|
122
|
|
|
exit(0); |
|
|
|
|
|
|
123
|
|
|
}); |
|
124
|
|
|
|
|
125
|
|
|
// Start processing queues |
|
126
|
|
|
$queue->doWork(); |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths