2021-12-03 03:01:39 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/** @file */
|
2017-08-23 01:29:51 +00:00
|
|
|
|
|
|
|
namespace Zotlabs\Daemon;
|
|
|
|
|
2018-06-05 01:40:11 +00:00
|
|
|
use Zotlabs\Lib\Libsync;
|
2018-06-01 04:05:09 +00:00
|
|
|
|
2021-12-03 03:01:39 +00:00
|
|
|
class Importfile
|
|
|
|
{
|
|
|
|
|
|
|
|
public static function run($argc, $argv)
|
|
|
|
{
|
2017-08-23 01:29:51 +00:00
|
|
|
|
2021-12-03 03:01:39 +00:00
|
|
|
logger('Importfile: ' . print_r($argv, true));
|
2017-08-23 01:29:51 +00:00
|
|
|
|
2021-12-03 03:01:39 +00:00
|
|
|
if ($argc < 3) {
|
|
|
|
return;
|
|
|
|
}
|
2017-08-23 03:32:02 +00:00
|
|
|
|
2021-12-03 03:01:39 +00:00
|
|
|
$channel = channelx_by_n($argv[1]);
|
|
|
|
if (! $channel) {
|
|
|
|
return;
|
|
|
|
}
|
2017-08-23 01:29:51 +00:00
|
|
|
|
2021-12-03 03:01:39 +00:00
|
|
|
$srcfile = $argv[2];
|
|
|
|
$folder = (($argc > 3) ? $argv[3] : '');
|
|
|
|
$dstname = (($argc > 4) ? $argv[4] : '');
|
2017-08-23 01:29:51 +00:00
|
|
|
|
2021-12-03 03:01:39 +00:00
|
|
|
$hash = random_string();
|
2017-08-23 01:29:51 +00:00
|
|
|
|
2021-12-03 03:01:39 +00:00
|
|
|
$arr = [
|
|
|
|
'src' => $srcfile,
|
|
|
|
'filename' => (($dstname) ? $dstname : basename($srcfile)),
|
|
|
|
'hash' => $hash,
|
|
|
|
'allow_cid' => $channel['channel_allow_cid'],
|
|
|
|
'allow_gid' => $channel['channel_allow_gid'],
|
|
|
|
'deny_cid' => $channel['channel_deny_cid'],
|
|
|
|
'deny_gid' => $channel['channel_deny_gid'],
|
|
|
|
'preserve_original' => true,
|
|
|
|
'replace' => true
|
|
|
|
];
|
2017-08-23 01:29:51 +00:00
|
|
|
|
2021-12-03 03:01:39 +00:00
|
|
|
if ($folder) {
|
|
|
|
$arr['folder'] = $folder;
|
|
|
|
}
|
2017-08-23 01:29:51 +00:00
|
|
|
|
2021-12-03 03:01:39 +00:00
|
|
|
attach_store($channel, $channel['channel_hash'], 'import', $arr);
|
2017-08-23 01:29:51 +00:00
|
|
|
|
2021-12-03 03:01:39 +00:00
|
|
|
$sync = attach_export_data($channel, $hash);
|
|
|
|
if ($sync) {
|
|
|
|
Libsync::build_sync_packet($channel['channel_id'], array('file' => array($sync)));
|
|
|
|
}
|
2017-08-23 01:29:51 +00:00
|
|
|
|
2021-12-03 03:01:39 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-08-23 01:29:51 +00:00
|
|
|
}
|