]> git.mxchange.org Git - friendica.git/blob - src/Worker/SpoolPost.php
Fix mods/README.md format
[friendica.git] / src / Worker / SpoolPost.php
1 <?php
2 /**
3  * @file src/Worker/SpoolPost.php
4  * @brief Posts items that wer spooled because they couldn't be posted.
5  */
6 namespace Friendica\Worker;
7
8 use Friendica\Core\Config;
9 use Friendica\Core\Logger;
10 use Friendica\Model\Item;
11
12 require_once "include/items.php";
13
14 class SpoolPost {
15         public static function execute() {
16                 $path = get_spoolpath();
17
18                 if (($path != '') && is_writable($path)){
19                         if ($dh = opendir($path)) {
20                                 while (($file = readdir($dh)) !== false) {
21
22                                         // It is not named like a spool file, so we don't care.
23                                         if (substr($file, 0, 5) != "item-") {
24                                                 continue;
25                                         }
26
27                                         $fullfile = $path."/".$file;
28
29                                         // We don't care about directories either
30                                         if (filetype($fullfile) != "file") {
31                                                 continue;
32                                         }
33
34                                         // We can't read or write the file? So we don't care about it.
35                                         if (!is_writable($fullfile) || !is_readable($fullfile)) {
36                                                 continue;
37                                         }
38
39                                         $arr = json_decode(file_get_contents($fullfile), true);
40
41                                         // If it isn't an array then it is no spool file
42                                         if (!is_array($arr)) {
43                                                 continue;
44                                         }
45
46                                         // Skip if it doesn't seem to be an item array
47                                         if (!isset($arr['uid']) && !isset($arr['uri']) && !isset($arr['network'])) {
48                                                 continue;
49                                         }
50
51                                         $result = Item::insert($arr);
52
53                                         Logger::log("Spool file ".$file." stored: ".$result, Logger::DEBUG);
54                                         unlink($fullfile);
55                                 }
56                                 closedir($dh);
57                         }
58                 }
59         }
60 }