private function upgradeFiles() { $this->db->beginTransaction(); $sel = $this->db->prepare("SELECT id, name, data FROM node WHERE class = 'file'"); $sel->execute(); $upd = $this->db->prepare("UPDATE node SET name = ?, data = ? WHERE id = ?"); $storage = $this->conf['filestorage']; $count1 = $count2 = 0; while ($row = $sel->fetch(PDO::FETCH_ASSOC)) { $row = array_merge($row, (array) @unserialize($row['data'])); $data = unserialize($row['data']); // Исправляем случайно закравшийся мусор в виде урлов. if (strlen($fileName = $row['filename']) != ($len = strcspn($fileName, '?&'))) { $fileName = $len ? substr($fileName, 0, $len) : 'unnamed'; } $old = os::path($storage, $row['filepath']); $new = os::path($storage, $newpath = os::path(dirname($row['filepath']), $fileName = os::getCleanFilename($fileName))); // reverse if (false) { if (file_exists($new) and !file_exists($old)) { rename($new, $old); } } else { if (file_exists($old) and !file_exists($new)) { $this->log(' ' . $row['filepath'] . ' => ' . $newpath); $count1++; // rename($old, $new); } else { $count2++; } } $data['filepath'] = $newpath; $data['filename'] = $fileName; $upd->execute(array($fileName, serialize($data), $row['id'])); } $this->db->commit(); $this->log(sprintf('%u files renamed, %u not changed.', $count1, $count2)); }