Created
September 10, 2013 06:18
-
-
Save 0x46616c6b/6505621 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require __DIR__ . '/vendor/autoload.php'; | |
use Guzzle\Http\Client as HttpClient; | |
use Predis\Client as RedisClient; | |
$redis = new RedisClient(); | |
$apiKey = '5P5SIaxS644YqeDbz6sFsT4ATJ2NkJhe'; | |
$currentTimestamp = time(); | |
$threshold = 60 * 60 * 24 * 30; // 30 days | |
$limitTimestamp = ($currentTimestamp - $threshold) * 1000; | |
$count = 0; | |
$pads = array(); | |
foreach ($redis->keys('pad:*') as $pad) { | |
$padId = preg_replace('/pad:/', '', $pad); | |
$padId = substr( | |
$padId, | |
0, | |
strpos($padId, ':') | |
); | |
if (in_array($padId, $pads)) continue; | |
$pads[] = $padId; | |
} | |
echo count($pads) . "\n"; | |
$client = new HttpClient('http://localhost:9001'); | |
foreach ($pads as $padId) { | |
$request = $client->get( | |
sprintf( | |
'/api/1/getLastEdited?apikey=%s&padID=%s', | |
$apiKey, | |
$padId | |
) | |
); | |
$data = $request->send()->getBody(); | |
$attr = json_decode($data, true); | |
if ($attr['code'] == 0) { | |
$lastEdited = $attr['data']['lastEdited']; | |
if (isset($lastEdited)) { | |
if ($lastEdited < $limitTimestamp) { | |
$request = $client->get( | |
sprintf( | |
'/api/1/deletePad?apikey=%s&padID=%s', | |
$apiKey, | |
$padId | |
) | |
); | |
$request->send(); | |
echo $padId . " wurde gelöscht" . "\n"; | |
echo "Letzte Benutzung: " . date('d.m.Y H:i', $lastEdited / 1000) . "\n\n"; | |
$count++; | |
} | |
} | |
} | |
} | |
echo $count . " Pads wurden gelöscht!"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment