aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Daemon/Importfile.php
blob: c68ed21cfd76607e4e637e41aee60fedbc25818d (plain) (blame)
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
<?php /** @file */

namespace Zotlabs\Daemon;

class Importfile {

	static public function run($argc,$argv){

		logger('Importfile: ' . print_r($argv,true));

		if($argc < 3)
			return;

		$channel = channelx_by_n($argv[1]);
		if(! $channel)
			return;

		$srcfile = $argv[2];
		$folder  = (($argc > 3) ? $argv[3] : '');
		$dstname = (($argc > 4) ? $argv[4] : '');

		$hash = random_string();

		$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
		];

		if($folder)
			$arr['folder'] = $folder;

		attach_store($channel,$channel['channel_hash'],'import',$arr);

		$sync = attach_export_data($channel,$hash);
		if($sync)
			build_sync_packet($channel['channel_id'],array('file' => array($sync)));
	
		return;
	}
}