Skip to content

Commit b82b9bb

Browse files
committed
new command: gh > delete database
1 parent 2f08a49 commit b82b9bb

File tree

4 files changed

+31
-14
lines changed

4 files changed

+31
-14
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ To search through your GitHub Enterprise instance replace `gh` by `ghe`.
7878
* `gh > login`
7979
* `gh > logout`
8080
* `gh > delete cache`
81+
* `gh > delete database`
8182
* `gh > update`
8283
* `gh > activate autoupdate`
8384
* `gh > deactivate autoupdate`

action.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@
5555
echo 'Successfully deleted cache';
5656
break;
5757

58+
case 'delete-database':
59+
Workflow::deleteDatabase();
60+
echo 'Successfully deleted database';
61+
break;
62+
5863
case 'refresh-cache':
5964
$curl = new Curl();
6065
foreach (explode(',', $parts[2]) as $url) {

search.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ private static function addSystemCommands()
485485
$cmds = array(
486486
'delete cache' => 'Delete GitHub Cache',
487487
'logout' => 'Log out this workflow',
488+
'delete database' => 'Delete database (contains login, config and cache)',
488489
'update' => 'Update this Alfred workflow'
489490
);
490491
if (Workflow::getConfig('autoupdate', true)) {

workflow.php

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class Workflow
1111

1212
private static $filePids;
1313

14+
private static $fileDb;
1415
/** @var PDO */
1516
private static $db;
1617
/** @var PDOStatement[] */
@@ -48,17 +49,11 @@ public static function init($enterprise = false, $query = null, $hotkey = false)
4849

4950
self::$filePids = $dataDir . '/pid';
5051

51-
$fileDb = $dataDir . '/db.sqlite';
52-
$exists = file_exists($fileDb);
53-
self::$db = new PDO('sqlite:' . $fileDb, null, null);
52+
self::$fileDb = $dataDir . '/db.sqlite';
53+
$exists = file_exists(self::$fileDb);
54+
self::$db = new PDO('sqlite:' . self::$fileDb, null, null);
5455
if (!$exists) {
55-
self::$db->exec('
56-
CREATE TABLE config (
57-
key TEXT PRIMARY KEY,
58-
value TEXT
59-
)
60-
');
61-
self::createRequestCacheTable();
56+
self::createTables();
6257
}
6358

6459
if (self::$enterprise) {
@@ -342,18 +337,33 @@ public static function checkUpdate()
342337
return version_compare($version, self::VERSION) > 0;
343338
}
344339

345-
private static function createRequestCacheTable()
340+
private static function createTables()
346341
{
342+
self::$db->exec('
343+
CREATE TABLE config (
344+
key TEXT PRIMARY KEY NOT NULL,
345+
value TEXT
346+
) WITHOUT ROWID
347+
');
348+
347349
self::$db->exec('
348350
CREATE TABLE request_cache (
349-
url TEXT PRIMARY KEY,
350-
timestamp INTEGER,
351+
url TEXT PRIMARY KEY NOT NULL,
352+
timestamp INTEGER NOT NULL,
351353
etag TEXT,
352354
content TEXT,
353355
refresh INTEGER,
354356
parent TEXT
355-
)
357+
) WITHOUT ROWID
356358
');
359+
self::$db->exec('CREATE INDEX parent_url ON request_cache(parent) WHERE parent IS NOT NULL');
360+
}
361+
362+
public static function deleteDatabase()
363+
{
364+
self::closeCursors();
365+
self::$db = null;
366+
unlink(self::$fileDb);
357367
}
358368

359369
public static function addItem(Item $item, $check = true)

0 commit comments

Comments
 (0)