/** * Rename the file in its current directory on disk. * * Also update meta data in DB. * * @access public * @param string new name (without path!) * @return boolean true on success, false on failure */ function rename_to($newname) { $old_file_name = $this->get_name(); // rename() will fail if newname already exists on windows // if it doesn't work that way on linux we need the extra check below // but then we have an integrity issue!! :( if (file_exists($this->_dir . $newname)) { syslog_insert(sprintf('File %s could not be renamed to %s', '<b>' . $old_file_name . '</b>', '<b>' . $newname . '</b>'), 'info', 'file', $this->ID); return false; } global $DB; $DB->begin(); $oldname = $this->get_name(); if ($this->is_dir()) { // modify folder content file paths in db $rel_dir = dirname($this->_rdfp_rel_path) . '/'; if ($rel_dir == './') { $rel_dir = ''; } $rel_dir = $rel_dir . $newname . '/'; $full_dir = $this->_dir . $newname . '/'; $temp_Filelist = new Filelist($this->_FileRoot, $this->_adfp_full_path); $temp_Filelist->load(); while ($temp_File = $temp_Filelist->get_next()) { $temp_File->modify_path($rel_dir, $full_dir); } } if (!@rename($this->_adfp_full_path, $this->_dir . $newname)) { // Rename will fail if $newname already exists (at least on windows) syslog_insert(sprintf('File %s could not be renamed to %s', '<b>' . $old_file_name . '</b>', '<b>' . $newname . '</b>'), 'info', 'file', $this->ID); $DB->rollback(); return false; } // Delete thumb caches for old name: // Note: new name = new usage : there is a fair chance we won't need the same cache sizes in the new loc. $this->rm_cache(); // Get Meta data (before we change name) (we may need to update it later): $this->load_meta(); $this->_name = $newname; $this->Filetype = NULL; // depends on name $rel_dir = dirname($this->_rdfp_rel_path) . '/'; if ($rel_dir == './') { $rel_dir = ''; } $this->_rdfp_rel_path = $rel_dir . $this->_name; $this->_adfp_full_path = $this->_dir . $this->_name; $this->_md5ID = md5($this->_adfp_full_path); if ($this->meta == 'loaded') { // We have meta data, we need to deal with it: // unchanged : $this->set( 'root_type', $this->_FileRoot->type ); // unchanged : $this->set( 'root_ID', $this->_FileRoot->in_type_ID ); $this->set('path', $this->_rdfp_rel_path); // Record to DB: if (!$this->dbupdate()) { // Update failed, try to rollback the rename on disk: if (!@rename($this->_adfp_full_path, $this->_dir . $oldname)) { // rename failed $DB->rollback(); syslog_insert(sprintf('File %s could not be renamed to %s', '<b>' . $old_file_name . '</b>', '<b>' . $newname . '</b>'), 'info', 'file', $this->ID); return false; } // Maybe needs a specific error message here, the db and the disk is out of sync syslog_insert(sprintf('File %s could not be renamed to %s', '<b>' . $old_file_name . '</b>', '<b>' . $newname . '</b>'), 'info', 'file', $this->ID); return false; } } else { // There might be some old meta data to *recycle* in the DB... // This can happen if there has been a file in the same location in the past and if that file // has been manually deleted or moved since then. When the new file arrives here, we'll recover // the zombie meta data and we don't reset it on purpose. Actually, we consider that the meta data // has been *accidentaly* lost and that the user is attempting to recover it by putting back the // file where it was before. Of course the logical way would be to put back the file manually, but // experience proves that users are inconsistent! $this->load_meta(); } $DB->commit(); syslog_insert(sprintf('File %s was renamed to %s', '<b>' . $old_file_name . '</b>', '<b>' . $newname . '</b>'), 'info', 'file', $this->ID); return true; }
/** * Create links between users and image files from the users profile_pictures folder */ function create_profile_picture_links() { global $DB; load_class('files/model/_filelist.class.php', 'Filelist'); load_class('files/model/_fileroot.class.php', 'FileRoot'); $path = 'profile_pictures'; $FileRootCache =& get_FileRootCache(); $UserCache =& get_UserCache(); // SQL query to get all users and limit by page below $users_SQL = new SQL(); $users_SQL->SELECT('*'); $users_SQL->FROM('T_users'); $users_SQL->ORDER_BY('user_ID'); $page = 0; $page_size = 100; while (count($UserCache->cache) > 0 || $page == 0) { // Load users by 100 at one time to avoid errors about memory exhausting $users_SQL->LIMIT($page * $page_size . ', ' . $page_size); $UserCache->clear(); $UserCache->load_by_sql($users_SQL); while (($iterator_User =& $UserCache->get_next()) != NULL) { // Iterate through UserCache) $FileRootCache->clear(); $user_FileRoot =& $FileRootCache->get_by_type_and_ID('user', $iterator_User->ID); if (!$user_FileRoot) { // User FileRoot doesn't exist continue; } $ads_list_path = get_canonical_path($user_FileRoot->ads_path . $path); // Previously uploaded avatars if (!is_dir($ads_list_path)) { // profile_picture folder doesn't exists in the user root dir continue; } $user_avatar_Filelist = new Filelist($user_FileRoot, $ads_list_path); $user_avatar_Filelist->load(); if ($user_avatar_Filelist->count() > 0) { // profile_pictures folder is not empty $info_content = ''; $LinkOwner = new LinkUser($iterator_User); while ($lFile =& $user_avatar_Filelist->get_next()) { // Loop through all Files: $fileName = $lFile->get_name(); if (process_filename($fileName)) { // The file has invalid file name, don't create in the database // TODO: asimo> we should collect each invalid file name here, and send an email to the admin continue; } $lFile->load_meta(true); if ($lFile->is_image()) { $lFile->link_to_Object($LinkOwner); } } } } // Increase page number to get next portion of users $page++; } // Clear cache data $UserCache->clear(); $FileRootCache->clear(); }
if ($UserSettings->param_Request('fm_dirsnotattop', 'fm_dirsnotattop', 'integer', 0)) { $fm_Filelist->_dirs_not_at_top = true; } if ($UserSettings->param_Request('fm_recursivedirsize', 'fm_recursivedirsize', 'integer', 0)) { $fm_Filelist->_use_recursive_dirsize = true; } if ($UserSettings->param_Request('fm_showhidden', 'fm_showhidden', 'integer', 0)) { $fm_Filelist->_show_hidden_files = true; } if (param('fm_flatmode', '', NULL, true)) { $fm_Filelist->flatmode = true; } /* * Load Filelist (with meta data): */ $fm_Filelist->load(); // Sort Filelist param('fm_order', 'string', NULL, true); if (!in_array($fm_order, array('name', 'path', 'type', 'size', 'lastmod', 'perms', 'fsowner', 'fsgroup'))) { $fm_order = NULL; } param('fm_orderasc', '', NULL, true); $fm_Filelist->sort($fm_order, $fm_orderasc); switch ($action) { case 'download': // TODO: We don't need the Filelist, move UP! // TODO: provide optional zip formats (tgz, ..) - the used lib provides more.. // TODO: use "inmemory"=>false, so that you can download bigger archives faster! $action_title = T_('Download'); if (!$selected_Filelist->count()) { $Messages->add(T_('Nothing selected.'), 'error');