Author: walkor (walkor@workerman.net)
コード例 #1
0
ファイル: Database.php プロジェクト: vojtajina/sitellite
 function _getBinary($collection, $id, $field)
 {
     loader_import('saf.File.Store');
     $fs = new FileStore($this->filestore_path);
     $data = $fs->get($id . '_' . $field . '_' . $collection);
     if (!$data) {
         $this->error = $fs->error;
         return false;
     }
     return $data;
 }
コード例 #2
0
ファイル: FileStore.class.php プロジェクト: fulldump/8
 /**
  * Documentar esto
  */
 private static function loadData()
 {
     if (self::$data == null) {
         if (file_exists(self::file)) {
             self::$data = unserialize(file_get_contents(self::file));
         } else {
             self::$data = array();
         }
     }
 }
コード例 #3
0
 /**
  * Show a deleted file version requested by the visitor.
  */
 function showFile($key)
 {
     global $wgOut;
     $wgOut->disable();
     $store = FileStore::get('deleted');
     $store->stream($key);
 }
コード例 #4
0
 /**
  * Moves an image from a safe private location
  * Caller is responsible for clearing caches
  * @param File $oimage
  * @returns mixed, string timestamp on success, false on failure
  */
 function makeOldImagePublic($oimage)
 {
     $transaction = new FSTransaction();
     if (!FileStore::lock()) {
         wfDebug(__METHOD__ . " could not acquire filestore lock\n");
         return false;
     }
     $store = FileStore::get('deleted');
     if (!$store) {
         wfDebug(__METHOD__ . ": skipping row with no file.\n");
         return false;
     }
     $key = $oimage->sha1 . '.' . $oimage->getExtension();
     $destDir = $oimage->getArchivePath();
     if (!is_dir($destDir)) {
         wfMkdirParents($destDir);
     }
     $destPath = $destDir . DIRECTORY_SEPARATOR . $oimage->archive_name;
     // Check if any other stored revisions use this file;
     // if so, we shouldn't remove the file from the hidden
     // archives so they will still work. Check hidden files first.
     $useCount = $this->dbw->selectField('oldimage', '1', array('oi_sha1' => $oimage->sha1, 'oi_deleted & ' . File::DELETED_FILE => File::DELETED_FILE), __METHOD__, array('FOR UPDATE'));
     // Check the rest of the deleted archives too.
     // (these are the ones that don't show in the image history)
     if (!$useCount) {
         $useCount = $this->dbw->selectField('filearchive', '1', array('fa_storage_group' => 'deleted', 'fa_storage_key' => $key), __METHOD__, array('FOR UPDATE'));
     }
     if ($useCount == 0) {
         wfDebug(__METHOD__ . ": nothing else using {$oimage->sha1}, will deleting after\n");
         $flags = FileStore::DELETE_ORIGINAL;
     } else {
         $flags = 0;
     }
     $transaction->add($store->export($key, $destPath, $flags));
     wfDebug(__METHOD__ . ": set db items, applying file transactions\n");
     $transaction->commit();
     FileStore::unlock();
     $m = explode('!', $oimage->archive_name, 2);
     $timestamp = $m[0];
     return $timestamp;
 }
コード例 #5
0
ファイル: Image.php プロジェクト: Jobava/diacritice-meta-repo
 /**
  * Restore all or specified deleted revisions to the given file.
  * Permissions and logging are left to the caller.
  *
  * May throw database exceptions on error.
  *
  * @param $versions set of record ids of deleted items to restore,
  *                    or empty to restore all revisions.
  * @return the number of file revisions restored if successful,
  *         or false on failure
  */
 function restore($versions = array(), $Unsuppress = false)
 {
     global $wgUser;
     if (!FileStore::lock()) {
         wfDebug(__METHOD__ . " could not acquire filestore lock\n");
         return false;
     }
     $transaction = new FSTransaction();
     try {
         $dbw = wfGetDB(DB_MASTER);
         $dbw->begin();
         // Re-confirm whether this image presently exists;
         // if no we'll need to create an image record for the
         // first item we restore.
         $exists = $dbw->selectField('image', '1', array('img_name' => $this->name), __METHOD__);
         // Fetch all or selected archived revisions for the file,
         // sorted from the most recent to the oldest.
         $conditions = array('fa_name' => $this->name);
         if ($versions) {
             $conditions['fa_id'] = $versions;
         }
         $result = $dbw->select('filearchive', '*', $conditions, __METHOD__, array('ORDER BY' => 'fa_timestamp DESC'));
         if ($dbw->numRows($result) < count($versions)) {
             // There's some kind of conflict or confusion;
             // we can't restore everything we were asked to.
             wfDebug(__METHOD__ . ": couldn't find requested items\n");
             $dbw->rollback();
             FileStore::unlock();
             return false;
         }
         if ($dbw->numRows($result) == 0) {
             // Nothing to do.
             wfDebug(__METHOD__ . ": nothing to do\n");
             $dbw->rollback();
             FileStore::unlock();
             return true;
         }
         $revisions = 0;
         while ($row = $dbw->fetchObject($result)) {
             if ($Unsuppress) {
                 // Currently, fa_deleted flags fall off upon restore, lets be careful about this
             } else {
                 if ($row->fa_deleted & Revision::DELETED_RESTRICTED && !$wgUser->isAllowed('hiderevision')) {
                     // Skip restoring file revisions that the user cannot restore
                     continue;
                 }
             }
             $revisions++;
             $store = FileStore::get($row->fa_storage_group);
             if (!$store) {
                 wfDebug(__METHOD__ . ": skipping row with no file.\n");
                 continue;
             }
             if ($revisions == 1 && !$exists) {
                 $destDir = wfImageDir($row->fa_name);
                 if (!is_dir($destDir)) {
                     wfMkdirParents($destDir);
                 }
                 $destPath = $destDir . DIRECTORY_SEPARATOR . $row->fa_name;
                 // We may have to fill in data if this was originally
                 // an archived file revision.
                 if (is_null($row->fa_metadata)) {
                     $tempFile = $store->filePath($row->fa_storage_key);
                     $magic = MimeMagic::singleton();
                     $mime = $magic->guessMimeType($tempFile, true);
                     $media_type = $magic->getMediaType($tempFile, $mime);
                     list($major_mime, $minor_mime) = self::splitMime($mime);
                     $handler = MediaHandler::getHandler($mime);
                     if ($handler) {
                         $metadata = $handler->getMetadata($image, $tempFile);
                     } else {
                         $metadata = '';
                     }
                 } else {
                     $metadata = $row->fa_metadata;
                     $major_mime = $row->fa_major_mime;
                     $minor_mime = $row->fa_minor_mime;
                     $media_type = $row->fa_media_type;
                 }
                 $table = 'image';
                 $fields = array('img_name' => $row->fa_name, 'img_size' => $row->fa_size, 'img_width' => $row->fa_width, 'img_height' => $row->fa_height, 'img_metadata' => $metadata, 'img_bits' => $row->fa_bits, 'img_media_type' => $media_type, 'img_major_mime' => $major_mime, 'img_minor_mime' => $minor_mime, 'img_description' => $row->fa_description, 'img_user' => $row->fa_user, 'img_user_text' => $row->fa_user_text, 'img_timestamp' => $row->fa_timestamp);
             } else {
                 $archiveName = $row->fa_archive_name;
                 if ($archiveName == '') {
                     // This was originally a current version; we
                     // have to devise a new archive name for it.
                     // Format is <timestamp of archiving>!<name>
                     $archiveName = wfTimestamp(TS_MW, $row->fa_deleted_timestamp) . '!' . $row->fa_name;
                 }
                 $destDir = wfImageArchiveDir($row->fa_name);
                 if (!is_dir($destDir)) {
                     wfMkdirParents($destDir);
                 }
                 $destPath = $destDir . DIRECTORY_SEPARATOR . $archiveName;
                 $table = 'oldimage';
                 $fields = array('oi_name' => $row->fa_name, 'oi_archive_name' => $archiveName, 'oi_size' => $row->fa_size, 'oi_width' => $row->fa_width, 'oi_height' => $row->fa_height, 'oi_bits' => $row->fa_bits, 'oi_description' => $row->fa_description, 'oi_user' => $row->fa_user, 'oi_user_text' => $row->fa_user_text, 'oi_timestamp' => $row->fa_timestamp);
             }
             $dbw->insert($table, $fields, __METHOD__);
             // @todo this delete is not totally safe, potentially
             $dbw->delete('filearchive', array('fa_id' => $row->fa_id), __METHOD__);
             // Check if any other stored revisions use this file;
             // if so, we shouldn't remove the file from the deletion
             // archives so they will still work.
             $useCount = $dbw->selectField('filearchive', 'COUNT(*)', array('fa_storage_group' => $row->fa_storage_group, 'fa_storage_key' => $row->fa_storage_key), __METHOD__);
             if ($useCount == 0) {
                 wfDebug(__METHOD__ . ": nothing else using {$row->fa_storage_key}, will deleting after\n");
                 $flags = FileStore::DELETE_ORIGINAL;
             } else {
                 $flags = 0;
             }
             $transaction->add($store->export($row->fa_storage_key, $destPath, $flags));
         }
         $dbw->immediateCommit();
     } catch (MWException $e) {
         wfDebug(__METHOD__ . " caught error, aborting\n");
         $transaction->rollback();
         throw $e;
     }
     $transaction->commit();
     FileStore::unlock();
     if ($revisions > 0) {
         if (!$exists) {
             wfDebug(__METHOD__ . " restored {$revisions} items, creating a new current\n");
             // Update site_stats
             $site_stats = $dbw->tableName('site_stats');
             $dbw->query("UPDATE {$site_stats} SET ss_images=ss_images+1", __METHOD__);
             $this->purgeEverything();
         } else {
             wfDebug(__METHOD__ . " restored {$revisions} as archived versions\n");
             $this->purgeDescription();
         }
     }
     return $revisions;
 }
コード例 #6
0
ファイル: FileStore.php プロジェクト: negabaro/alfresco
 /**
  * Delete a file from the file store.
  * Caller's responsibility to make sure it's not being used by another row.
  *
  * File is not actually removed until transaction commit.
  * Should be protected by FileStore::lock() to avoid race conditions.
  *
  * @param $key storage key string
  * @throws FSException if file can't be deleted
  * @return FSTransaction
  */
 function delete($key)
 {
     $destPath = $this->filePath($key);
     if (false === $destPath) {
         throw new FSExcepton("file store does not contain file '{$key}'");
     } else {
         return FileStore::deleteFile($destPath);
     }
 }
コード例 #7
0
 function deletePermanently($title)
 {
     global $wgOut;
     $ns = $title->getNamespace();
     $t = $title->getDBkey();
     $id = $title->getArticleID();
     $cats = $title->getParentCategories();
     $dbw = wfGetDB(DB_MASTER);
     $dbw->begin();
     ####
     ## First delete entries, which are in direct relation with the page:
     ####
     # delete redirect...
     $dbw->delete('redirect', array('rd_from' => $id), __METHOD__);
     # delete external link...
     $dbw->delete('externallinks', array('el_from' => $id), __METHOD__);
     # delete language link...
     $dbw->delete('langlinks', array('ll_from' => $id), __METHOD__);
     # delete search index...
     $dbw->delete('searchindex', array('si_page' => $id), __METHOD__);
     # Delete restrictions for the page
     $dbw->delete('page_restrictions', array('pr_page' => $id), __METHOD__);
     # Delete page Links
     $dbw->delete('pagelinks', array('pl_from' => $id), __METHOD__);
     # delete category links
     $dbw->delete('categorylinks', array('cl_from' => $id), __METHOD__);
     # delete template links
     $dbw->delete('templatelinks', array('tl_from' => $id), __METHOD__);
     # read text entries for all revisions and delete them.
     $res = $dbw->select('revision', 'rev_text_id', "rev_page={$id}");
     while ($row = $dbw->fetchObject($res)) {
         $value = $row->rev_text_id;
         $dbw->delete('text', array('old_id' => $value), __METHOD__);
     }
     # In the table 'revision' : Delete all the revision of the page where 'rev_page' = $id
     $dbw->delete('revision', array('rev_page' => $id), __METHOD__);
     # delete image links
     $dbw->delete('imagelinks', array('il_from' => $id), __METHOD__);
     ####
     ## then delete entries which are not in direct relation with the page:
     ####
     # Clean up recentchanges entries...
     $dbw->delete('recentchanges', array('rc_namespace' => $ns, 'rc_title' => $t), __METHOD__);
     # read text entries for all archived pages and delete them.
     $res = $dbw->select('archive', 'ar_text_id', array('ar_namespace' => $ns, 'ar_title' => $t));
     while ($row = $dbw->fetchObject($res)) {
         $value = $row->ar_text_id;
         $dbw->delete('text', array('old_id' => $value), __METHOD__);
     }
     # Clean archive entries...
     $dbw->delete('archive', array('ar_namespace' => $ns, 'ar_title' => $t), __METHOD__);
     # Clean up log entries...
     $dbw->delete('logging', array('log_namespace' => $ns, 'log_title' => $t), __METHOD__);
     # Clean up watchlist...
     $dbw->delete('watchlist', array('wl_namespace' => $ns, 'wl_title' => $t), __METHOD__);
     # In the table 'page' : Delete the page entry
     $dbw->delete('page', array('page_id' => $id), __METHOD__);
     ####
     ## If the article belongs to a category, update category counts
     ####
     if (!empty($cats)) {
         foreach ($cats as $parentcat => $currentarticle) {
             $catname = split(':', $parentcat, 2);
             $cat = Category::newFromName($catname[1]);
             $cat->refreshCounts();
         }
     }
     ####
     ## If an image is beeing deleted, some extra work needs to be done
     ####
     if ($ns == NS_IMAGE) {
         $file = wfFindFile($t);
         if ($file) {
             # Get all filenames of old versions:
             $fields = OldLocalFile::selectFields();
             $res = $dbw->select('oldimage', $fields, array('oi_name' => $t));
             while ($row = $dbw->fetchObject($res)) {
                 $oldLocalFile = OldLocalFile::newFromRow($row, $file->repo);
                 $path = $oldLocalFile->getArchivePath() . '/' . $oldLocalFile->getArchiveName();
                 try {
                     # Using the FileStore to delete the file
                     $transaction = FileStore::deleteFile($path);
                     $transaction->commit();
                 } catch (Exception $e) {
                     $wgOut->addHTML($e->getMessage());
                 }
             }
             $path = $file->getPath();
             try {
                 # Using the FileStore to delete the file itself
                 $transaction = FileStore::deleteFile($path);
                 $transaction->commit();
             } catch (Exception $e) {
                 $wgOut->addHTML($e->getMessage());
             }
         }
         # clean the filearchive for the given filename:
         $fa_archive_name = array();
         $res = $dbw->select('filearchive', 'fa_storage_key', array('fa_name' => $t));
         while ($row = $dbw->fetchObject($res)) {
             $key = $row->fa_storage_key;
             # Using the FileStore to delete the file
             $store = FileStore::get('deleted');
             $transaction = $store->delete($key);
             $transaction->commit();
         }
         # Delete old db entries of the image:
         $dbw->delete('oldimage', array('oi_name' => $t), __METHOD__);
         # Delete archive entries of the image:
         $dbw->delete('filearchive', array('fa_name' => $t), __METHOD__);
         # Delete image entry:
         $dbw->delete('image', array('img_name' => $t), __METHOD__);
         $dbw->commit();
         $linkCache = LinkCache::singleton();
         $linkCache->clear();
     }
 }
コード例 #8
0
 /**
  * Show a deleted file version requested by the visitor.
  */
 function showFile($key)
 {
     global $wgOut, $wgRequest;
     $wgOut->disable();
     # We mustn't allow the output to be Squid cached, otherwise
     # if an admin previews a deleted image, and it's cached, then
     # a user without appropriate permissions can toddle off and
     # nab the image, and Squid will serve it
     $wgRequest->response()->header('Expires: ' . gmdate('D, d M Y H:i:s', 0) . ' GMT');
     $wgRequest->response()->header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
     $wgRequest->response()->header('Pragma: no-cache');
     $store = FileStore::get('deleted');
     $store->stream($key);
 }
コード例 #9
0
ファイル: Database.class.php プロジェクト: fulldump/8
 /**
  * Implementa la interfaz FileStorable
  */
 public static function store_config()
 {
     FileStore::write(__CLASS__, self::$config);
 }
コード例 #10
0
ファイル: Photo.php プロジェクト: fulldecent/cameralife
 /**
  * isCacheMissing function.
  * Return true if thumbnail is missing or if needed _mod is missing
  *
  * @access public
  * @return bool
  */
 public function isCacheMissing()
 {
     if ($this->record['modified'] == '1') {
         return true;
         //legacy before 2.7
     }
     $cacheBucket = FileStore::fileStoreWithName('other');
     if ($this->record['modified']) {
         $filename = '/' . $this->record['id'] . '_mod.' . $this->extension;
         $stat = $cacheBucket->listFiles($filename);
         if (!count($stat)) {
             return true;
         }
     }
     $sizes = array();
     $sizes[] = Preferences::valueForModuleWithKey('CameraLife', 'thumbsize');
     $sizes[] = Preferences::valueForModuleWithKey('CameraLife', 'scaledsize');
     $options = Preferences::valueForModuleWithKey('CameraLife', 'optionsizes');
     preg_match_all('/[0-9]+/', $options, $matches);
     $sizes = array_merge($sizes, $matches[0]);
     foreach ($sizes as $cursize) {
         $filename = '/' . $this->record['id'] . '_' . $cursize . '.' . $this->extension;
         $stat = $cacheBucket->listFiles($filename);
         if (!count($stat)) {
             return true;
         }
     }
     return false;
 }
コード例 #11
0
ファイル: Folder.php プロジェクト: fulldecent/cameralife
 /**
  * Does a quick compare of Database and FileStore and checks if they are same
  *
  * @return true or false
  */
 public function fsck()
 {
     $fileStore = FileStore::fileStoreWithName('photo');
     $fileStoreNewPhotos = $fileStore->listFiles();
     // path->basename format
     if (!count($fileStoreNewPhotos)) {
         throw new \Exception('No files were found in file store');
     }
     $result = Database::select('photos', 'id,filename,path,fsize', 'status!=9', 'ORDER BY path,filename');
     // Verify each photo in the DB
     while ($dbPhoto = $result->fetchAssoc()) {
         $dbFilePath = rtrim('/' . ltrim($dbPhoto['path'], '/'), '/') . '/' . $dbPhoto['filename'];
         if (isset($fileStoreNewPhotos[$dbFilePath])) {
             unset($fileStoreNewPhotos[$dbFilePath]);
             continue;
         }
         return false;
     }
     return count($fileStoreNewPhotos) == 0;
 }
コード例 #12
0
ファイル: Config.class.php プロジェクト: fulldump/8
 private static function store_data()
 {
     FileStore::write(__CLASS__, self::$_data);
     return true;
 }