PluginProbe
Disk Usage Insights / 1.2
Disk Usage Insights v1.2
trunk 1.0 1.10 1.11 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9
← All changes | src/Domain/FileEntryRepository.php +4 -42 trunk1.2 View file →
@@ -1,15 +1,13 @@
1 1 <?php
2 2
3 3 namespace Mgleis\DiskUsageInsights\Domain;
4 4
5 -use PDO;
6 -
7 5 class FileEntryRepository {
8 6
9 - private PDO $db;
7 + private \PDO $db;
10 8
11 - public function __construct(PDO $db) {
9 + public function __construct(\PDO $db) {
12 10 $this->db = $db;
13 11 $this->initializeDatabase();
14 12 }
15 13
@@ -70,9 +68,9 @@
70 68 SELECT * FROM fileentries WHERE id =:id
71 69 ");
72 70 $stmt->bindValue(':id', $id);
73 71 $stmt->execute();
74 - $result = $stmt->fetch(PDO::FETCH_ASSOC);
72 + $result = $stmt->fetch(\PDO::FETCH_ASSOC);
75 73 if ($result === false) {
76 74 throw new \Exception(sprintf("No file entry with id %s found.", esc_html($id)));
77 75 }
78 76
@@ -83,44 +81,8 @@
83 81
84 82 return $entry;
85 83 }
86 84
87 - /**
88 - *
89 - * @param string $relativeFilename e.g. '/wp-content/plugins'
90 - * @throws \Exception
91 - * @return FileEntry|null
92 - */
93 - public function findByRelativeName(string $relativeFilename): ?FileEntry {
94 -
95 - $arr = explode('/', $relativeFilename);
96 - $parentId = 0; // root entry
97 - $result = null;
98 - foreach ($arr as $part) {
99 - $stmt = $this->db->prepare("
100 - SELECT * FROM fileentries WHERE parent_id = :parent_id AND name = :name;
101 - ");
102 - $stmt->bindValue(':parent_id', $parentId);
103 - $stmt->bindValue(':name', $part);
104 - $stmt->execute();
105 - $result = $stmt->fetch(PDO::FETCH_ASSOC);
106 - if ($result === false) {
107 - throw new \Exception(sprintf("Error finding %s", esc_html($relativeFilename)));
108 - }
109 - $parentId = $result['id'];
110 - }
111 -
112 - if ($result !== null) {
113 - $entry = new FileEntry();
114 - foreach ($result as $key => $value) {
115 - $entry->$key = $value;
116 - }
117 - return $entry;
118 - } else {
119 - return null;
120 - }
121 - }
122 -
123 85 private static $cache = [];
124 86 public function calcFullPath(FileEntry $fileEntry, string $root = ''): string {
125 87 $full = $fileEntry->name;
126 88 while ($fileEntry->parent_id != 0) {
@@ -158,9 +120,9 @@
158 120 $stmt = $this->db->prepare("
159 121 SELECT * FROM fileentries WHERE type in ($types) LIMIT $count OFFSET $skip
160 122 ");
161 123 $stmt->execute();
162 - $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
124 + $rows = $stmt->fetchAll(\PDO::FETCH_ASSOC);
163 125
164 126 $results = [];
165 127 foreach ($rows as $row) {
166 128 $entry = new FileEntry();