本文整理汇总了PHP中FilesModel::findMultipleFilesByFolder方法的典型用法代码示例。如果您正苦于以下问题:PHP FilesModel::findMultipleFilesByFolder方法的具体用法?PHP FilesModel::findMultipleFilesByFolder怎么用?PHP FilesModel::findMultipleFilesByFolder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FilesModel
的用法示例。
在下文中一共展示了FilesModel::findMultipleFilesByFolder方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: findMultiplePublishedMultiSRCContentElements
public static function findMultiplePublishedMultiSRCContentElements($arrIds, $arrExtensions, array $arrOptions = array())
{
if (!is_array($arrIds) || empty($arrIds) || !is_array($arrExtensions) || empty($arrExtensions)) {
return null;
}
foreach ($arrExtensions as $k => $v) {
if (!preg_match('/^[a-z0-9]{2,5}$/i', $v)) {
unset($arrExtensions[$k]);
}
}
$t = static::$strTable;
$objDatabase = \Database::getInstance();
// get names of parent tables (tl_news, tl_article, tl_calendar_events)
$objTable = $objDatabase->prepare("SELECT DISTINCT ptable FROM tl_content")->execute();
if ($objTable->numRows < 1) {
return null;
}
$arrReturn = null;
while ($objTable->next()) {
$strQuery = "\n SELECT c.id AS cid, c.ptable as ptable, c.pid as parent, c.multiSRC\n FROM tl_content c\n LEFT JOIN {$objTable->ptable} p ON p.id = c.pid\n WHERE c.multiSRC IS NOT NULL AND c.invisible = ''";
$objStatement = $objDatabase->prepare($strQuery);
if (\Database::getInstance()->fieldExists('published', $objTable->ptable)) {
$strQuery . " AND p.published = 1";
}
$objResult = $objStatement->execute();
if ($objResult->numRows < 1) {
return null;
}
while ($objResult->next()) {
$arrUuids = deserialize($objResult->multiSRC, true);
$objFiles = \FilesModel::findMultipleByUuids($arrUuids);
if ($objFiles === null) {
continue;
}
if (!$objFiles->copyright) {
continue;
}
if ($objFiles->type == 'folder') {
$objSubfiles = \FilesModel::findByPid($objFiles->uuid);
if ($objSubfiles === null) {
continue;
}
while ($objSubfiles->next()) {
// Skip subfolders
if ($objSubfiles->type == 'folder') {
$objFolderFiles = \FilesModel::findMultipleFilesByFolder($objSubfiles->path);
if ($objFolderFiles === null) {
continue;
}
while ($objFolderFiles->next()) {
if (!in_array($objFolderFiles->extension, $arrExtensions)) {
continue;
}
if (!$objFolderFiles->copyright) {
continue;
}
$arrReturn[] = (object) array_merge($objResult->row(), $objFolderFiles->row());
}
}
if (!in_array($objSubfiles->extension, $arrExtensions)) {
continue;
}
if (!$objSubfiles->copyright) {
continue;
}
$arrReturn[] = (object) array_merge($objResult->row(), $objSubfiles->row());
}
} else {
$arrReturn[] = (object) array_merge($objResult->row(), $objFiles->row());
}
}
}
return empty($arrReturn) ? null : $arrReturn;
}
示例2: syncFiles
/**
* Synchronize the file system with the database
*
* @return string The path to the synchronization log file
*
* @throws \Exception If a parent ID entry is missing
*/
public static function syncFiles()
{
// Try to raise the limits (see #7035)
@ini_set('memory_limit', -1);
@ini_set('max_execution_time', 0);
$objDatabase = \Database::getInstance();
// Lock the files table
$objDatabase->lockTables(array('tl_files'));
// Reset the "found" flag
$objDatabase->query("UPDATE tl_files SET found=''");
// Get a filtered list of all files
$objFiles = new \RecursiveIteratorIterator(new \Dbafs\Filter(new \RecursiveDirectoryIterator(TL_ROOT . '/' . \Config::get('uploadPath'), \FilesystemIterator::UNIX_PATHS | \FilesystemIterator::FOLLOW_SYMLINKS | \FilesystemIterator::SKIP_DOTS)), \RecursiveIteratorIterator::SELF_FIRST);
$strLog = 'system/tmp/' . md5(uniqid(mt_rand(), true));
// Open the log file
$objLog = new \File($strLog, true);
$objLog->truncate();
$arrModels = array();
// Create or update the database entries
foreach ($objFiles as $objFile) {
$strRelpath = str_replace(TL_ROOT . '/', '', $objFile->getPathname());
// Get all subfiles in a single query
if ($objFile->isDir()) {
$objSubfiles = \FilesModel::findMultipleFilesByFolder($strRelpath);
if ($objSubfiles !== null) {
while ($objSubfiles->next()) {
$arrModels[$objSubfiles->path] = $objSubfiles->current();
}
}
}
// Get the model
if (isset($arrModels[$strRelpath])) {
$objModel = $arrModels[$strRelpath];
} else {
$objModel = \FilesModel::findByPath($strRelpath);
}
if ($objModel === null) {
// Add a log entry
$objLog->append("[Added] {$strRelpath}");
// Get the parent folder
$strParent = dirname($strRelpath);
// Get the parent ID
if ($strParent == \Config::get('uploadPath')) {
$strPid = null;
} else {
$objParent = \FilesModel::findByPath($strParent);
if ($objParent === null) {
throw new \Exception("No parent entry for {$strParent}");
}
$strPid = $objParent->uuid;
}
// Create the file or folder
if (is_file(TL_ROOT . '/' . $strRelpath)) {
$objFile = new \File($strRelpath, true);
$objModel = new \FilesModel();
$objModel->pid = $strPid;
$objModel->tstamp = time();
$objModel->name = $objFile->name;
$objModel->type = 'file';
$objModel->path = $objFile->path;
$objModel->extension = $objFile->extension;
$objModel->found = 2;
$objModel->hash = $objFile->hash;
$objModel->uuid = $objDatabase->getUuid();
$objModel->save();
} else {
$objFolder = new \Folder($strRelpath);
$objModel = new \FilesModel();
$objModel->pid = $strPid;
$objModel->tstamp = time();
$objModel->name = $objFolder->name;
$objModel->type = 'folder';
$objModel->path = $objFolder->path;
$objModel->extension = '';
$objModel->found = 2;
$objModel->hash = $objFolder->hash;
$objModel->uuid = $objDatabase->getUuid();
$objModel->save();
}
} else {
// Check whether the MD5 hash has changed
$objResource = $objFile->isDir() ? new \Folder($strRelpath) : new \File($strRelpath);
$strType = $objModel->hash != $objResource->hash ? 'Changed' : 'Unchanged';
// Add a log entry
$objLog->append("[{$strType}] {$strRelpath}");
// Update the record
$objModel->found = 1;
$objModel->hash = $objResource->hash;
$objModel->save();
}
}
// Check for left-over entries in the DB
$objFiles = \FilesModel::findByFound('');
if ($objFiles !== null) {
//.........这里部分代码省略.........
示例3: importFromFilesystem
/**
* @param integer
* @param string
* Bilder aus Verzeichnis auf dem Server in Album einlesen
*/
public static function importFromFilesystem($intAlbumId, $strMultiSRC)
{
$images = array();
$objFilesModel = \FilesModel::findMultipleByUuids(explode(',', $strMultiSRC));
if ($objFilesModel === null) {
return;
}
while ($objFilesModel->next()) {
// Continue if the file has been processed or does not exist
if (isset($images[$objFilesModel->path]) || !file_exists(TL_ROOT . '/' . $objFilesModel->path)) {
continue;
}
// If item is a file, then store it in the array
if ($objFilesModel->type == 'file') {
$objFile = new \File($objFilesModel->path);
if ($objFile->isGdImage) {
$images[$objFile->path] = array('uuid' => $objFilesModel->uuid, 'basename' => $objFile->basename, 'path' => $objFile->path);
}
} else {
// If it is a directory, then store its files in the array
$objSubfilesModel = \FilesModel::findMultipleFilesByFolder($objFilesModel->path);
if ($objSubfilesModel === null) {
continue;
}
while ($objSubfilesModel->next()) {
// Skip subfolders
if ($objSubfilesModel->type == 'folder' || !is_file(TL_ROOT . '/' . $objSubfilesModel->path)) {
continue;
}
$objFile = new \File($objSubfilesModel->path);
if ($objFile->isGdImage) {
$images[$objFile->path] = array('uuid' => $objSubfilesModel->uuid, 'basename' => $objFile->basename, 'path' => $objFile->path);
}
}
}
}
if (count($images)) {
$uploadPath = GALLERY_CREATOR_UPLOAD_PATH;
$objPictures = \Database::getInstance()->prepare('SELECT * FROM tl_gallery_creator_pictures WHERE pid=?')->execute($intAlbumId);
$arrPictures['uuid'] = $objPictures->fetchEach('uuid');
$arrPictures['path'] = $objPictures->fetchEach('path');
foreach ($arrPictures['path'] as $path) {
$arrPictures['basename'][] = basename($path);
}
$objAlb = \MCupic\GalleryCreatorAlbumsModel::findById($intAlbumId);
foreach ($images as $image) {
// Prevent duplicate entries
if (in_array($image['uuid'], $arrPictures['uuid'])) {
continue;
}
// Prevent duplicate entries
if (in_array($image['basename'], $arrPictures['basename'])) {
continue;
}
\Input::setGet('importFromFilesystem', 'true');
if ($GLOBALS['TL_CONFIG']['gc_album_import_copy_files']) {
$strSource = $image['path'];
// Get the album upload directory
$objFolderModel = \FilesModel::findByUuid($objAlb->assignedDir);
$errMsg = 'Aborted import process, because there is no upload folder assigned to the album with ID ' . $objAlb->id . '.';
if ($objFolderModel === null) {
die($errMsg);
}
if ($objFolderModel->type != 'folder') {
die($errMsg);
}
if (!is_dir(TL_ROOT . '/' . $objFolderModel->path)) {
die($errMsg);
}
$strDestination = self::generateUniqueFilename($objFolderModel->path . '/' . basename($strSource));
if (is_file(TL_ROOT . '/' . $strSource)) {
//copy Image to the upload folder
$objFile = new \File($strSource);
$objFile->copyTo($strDestination);
\Dbafs::addResource($strSource);
}
self::createNewImage($objAlb->id, $strDestination);
} else {
self::createNewImage($objAlb->id, $image['path']);
}
}
}
}