-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathimport.php
More file actions
50 lines (39 loc) · 1.23 KB
/
Copy pathimport.php
File metadata and controls
50 lines (39 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
if (php_sapi_name()!='cli') {
die('ERROR: This script is only for command line.');
}
if (!file_exists(__DIR__ . '/config.php')) {
die("ERROR \nKyselo not installed.\n");
}
$config = require __DIR__ . '/config.php';
if (empty($argv[1]) || empty($argv[2])) {
die("ERROR \nBad import parameters. \nPlease specifiy: \n- RSS file \n- destination username\n");
}
if (!file_exists($argv[1])) {
die("ERROR \nCannot open file: " . $argv[1] . "\n");
}
require dirname(__FILE__) . "/lib/flight/autoload.php";
\flight\core\Loader::addDirectory(dirname(__FILE__) . '/lib' );
$db = new medoo(array(
'database_type' => 'sqlite',
'database_file' => dirname(__FILE__) . '/' . $config['database']
));
$blog = $db->get('blogs', '*', ['name'=>$argv[2]]);
if (!$blog) {
echo 'Blog not found, creating it...' . PHP_EOL;
$blogId = $db->insert('blogs', [
'name' => $argv[2],
'title' => $argv[2] . '\'s soup',
'about' => '(imported from backup)',
'avatar_url'=> '/st/img/undraw_unicorn.png',
'user_id' => 0
]);
if (!$blogId) {
die("ERROR \nBlog not created.\n");
}
$blog = $db->get('blogs', '*', ['id'=>$blogId]);
}
$import = new kyselo_mirror_soup($db);
echo "importing your feed...\n";
$import->importFeed($argv[1], $blog['id']);
echo "OK\n";