-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck.php
152 lines (129 loc) · 3.47 KB
/
check.php
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
require_once 'STFU.php';
class STFU_Check {
private $stfu;
private $folder;
private $root;
private $albums = array();
public function __construct($folder, $root) {
$this->stfu = new SimpleTerminalFlickrUtility('Albums Checker');
$this->folder = $folder;
$this->root = $root;
}
public function getAlbums() {
Color::text("List all albums...\t");
$sets = $this->stfu->api->photosets_getList();
Color::ok();
foreach($sets['photoset'] as $set) {
/*
var_dump($album);exit;
$title = $album['title']['_content'];
$title = iconv('UTF-8', 'ASCII//IGNORE', $title);
$this->albums[$album['id']] = $title;
*/
$album = new Album($set);
$this->albums[$album->name] = $album;
}
return $this->albums;
}
private function checkFolder($currentAlbum, $items) {
// search album
echo "\tExists?\t";
if (array_key_exists($currentAlbum, $this->albums)) {
Color::ok(false);
echo "\tNumber of elements?\t";
if ($this->albums[$currentAlbum]->nbItems == $items) {
Color::ok();
}
else {
Color::text("Folder has $items items, album has ".$this->albums[$currentAlbum]->nbItems, Color::red);
}
}
else {
Color::text("Fail", Color::red);
}
}
public function check() {
// first folder won't be iterated over, let's init it
$currentAlbum = SimpleTerminalFlickrUtility::folderToAlbum(realpath($this->folder), $this->root);
//var_dump($currentAlbum);
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($this->folder, FilesystemIterator::SKIP_DOTS),
RecursiveIteratorIterator::SELF_FIRST
);
$items = 0;
foreach ($iterator as $info) {
$path = $info->getRealpath();
if ($info->getFilename() == 'Thumbs.db') {
unlink($path);
echo "\nRemoved useless Thumbs.db\n";
continue;
}
// new folder reached
if ($info->isDir()) {
echo "\nChecking $currentAlbum ...";
// has items?
if ($items > 0) {
// search album
/*
echo "\tExists?\t";
if (array_key_exists($currentAlbum, $this->albums)) {
Color::ok(false);
echo "\tNumber of elements?\t";
if ($this->albums[$currentAlbum]->nbItems == $items) {
Color::ok();
}
else {
Color::text("Folder has $items items, album has ".$this->albums[$currentAlbum]->nbItems, Color::red);
}
}
else {
Color::text("Fail", Color::red);
}*/
$this->checkFolder($currentAlbum, $items);
}
else {
Color::text("\tEmpty", Color::green);
}
// switch to new album
$currentAlbum = SimpleTerminalFlickrUtility::folderToAlbum($path, $this->root);
$currentAlbum = iconv('UTF-8', 'ASCII//IGNORE', $currentAlbum);
$items = 0;
}
else {
$items++;
}
/*
$albumName = SimpleTerminalFlickrUtility::folderToAlbum($path, $this->root);
$albumName = iconv('UTF-8', 'ASCII//IGNORE', $albumName);
if ($albumName != $currentAlbum) {
$items = 1;
$currentAlbum = $albumName;
echo "$albumName\n";
$found = array_key_exists($albumName, $this->albums);
if ($found) {
Color::ok();
}
else {
Color::text("Not found\n", Color::red);
}
}
else {
$items++;
}*/
}
echo "\nChecking $currentAlbum ...";
$this->checkFolder($currentAlbum, $items);
}
public function exec() {
$this->getAlbums();
$this->check();
}
}
$root = 'Albums\\';
if (count($argv) < 2) {
Color::text("Usage: php ".$argv[0]." <folder>\n", Color::red);
exit;
}
$stfu = new STFU_Check($argv[1], $root);
$stfu->exec();