/// <summary>
    /// Copies the file binary to the file system.
    /// </summary>
    /// <param name="attachmentId">Attachment ID</param>
    /// <param name="name">Returning the attachment name</param>
    protected bool CopyToFileSystem(int attachmentId, ref string name)
    {
        // Copy the file from database to the file system
        AttachmentInfo ai = AttachmentInfoProvider.GetAttachmentInfo(attachmentId, true);
        if (ai != null)
        {
            name = ai.AttachmentName;

            // Ensure the physical file
            AttachmentInfoProvider.EnsurePhysicalFile(ai, GetSiteName(ai.AttachmentSiteID));

            return true;
        }

        return false;
    }
    /// <summary>
    /// Deletes the file binary from the database.
    /// </summary>
    /// <param name="attachmentId">Attachment ID</param>
    /// <param name="name">Returning the attachment name</param>
    protected bool DeleteFromDatabase(int attachmentId, ref string name)
    {
        // Delete the file in database and ensure it in the file system
        AttachmentInfo ai = AttachmentInfoProvider.GetAttachmentInfo(attachmentId, false);
        if (ai != null)
        {
            name = ai.AttachmentName;

            AttachmentInfoProvider.EnsurePhysicalFile(ai, GetSiteName(ai.AttachmentSiteID));

            // Clear the binary data
            ai.AttachmentBinary = null;
            ai.Generalized.UpdateData();

            return true;
        }

        return false;
    }
Beispiel #3
0
        protected void RunInternal()
        {
            try
            {
                RunningInternal = true;

                ProgressMessageBuffer.Add("Starting cleaning process...");

                var attachmentIDs = AttachmentInfoProvider
                                    .GetAttachments(null, "AttachmentName", false)
                                    .Select(att => att.AttachmentID);

                if (attachmentIDs == null)
                {
                    return;
                }

                var sites = SiteInfoProvider.GetSites();

                // Configure attachment storage setting keys. Mover won't work without this:
                SettingsKeyInfoProvider.SetValue("CMSStoreFilesInFileSystem", "True", false);
                SettingsKeyInfoProvider.SetValue("CMSStoreFilesInDatabase", "False", false);

                foreach (var aID in attachmentIDs)
                {
                    if (Cancelled)
                    {
                        RunningInternal = false;
                        Cancelled       = false;
                        return;
                    }

                    var att = AttachmentInfoProvider.GetAttachmentInfo(aID, false);

                    var attSite = sites.FirstOrDefault(s => s.SiteID == att.AttachmentSiteID);

                    if (attSite == null)
                    {
                        continue;
                    }

                    AttachmentInfoProvider.EnsurePhysicalFile(att, attSite.SiteName);

                    att.AttachmentBinary = null;
                    att.Generalized.UpdateData();

                    ProgressMessageBuffer.Add(att.AttachmentName + " copied to file system.");
                }

                ProgressMessageBuffer.Add("Cleaning Process Complete");

                RunningInternal = false;
            }
            catch (Exception e)
            {
                ProgressMessageBuffer.Add("ERROR --------------------------");
                ProgressMessageBuffer.Add(e.Message);
                ProgressMessageBuffer.Add(e.StackTrace);
                RunningInternal = false;
            }
        }