Jump to:

22970 Posts in 11572 Topics by 2823 members

General Questions

SilverStripe Forums » General Questions » Files uploaded via FTP vs CMS

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 858 Views
  • Rod
    Avatar
    Community Member
    12 Posts

    Files uploaded via FTP vs CMS Link to this post

    HI there,

    I have noticed that Silverstripe will not 'know about' files that are uploaded via the FTP until I 'look for new files' in the Files & Images tab of the CMS.

    Is there a way to change this behavior?

    The reason is that we have a process that automatically/periodically creates some files (exe's and tar.gs's) and uploads them to a folder under 'assets'. I'd like these to instantly be available on the web front end. i.e. I want to eliminate this step of having to log into the CMS and 'looking for new files' every time I add or remove a file through the FTP via the automated process.

    Any ideas?

    Thanks
    Liam

    PS, here is a sample of my code in case it is useful...

    Page.php file has a nuber of functions within the Page class that looks for these files, e.g.:

    function GetTheFiles() {
        return DataObject::get(
        $name = 'File',
        $filter = "ClassName = 'File' and Filename like 'assets/subfolder/subfolder2/%-nz-win-%'",
        $sort = "Name ASC",
        $join = "",
        $limit = "4"
        );
       }

    And the Page.ss template then displays them, e.g.:

    <% control GetTheFiles %>
    <li class="win"><a href="$URL">$Title</a></li>
    <% end_control %>

  • MarcusDalgren
    Avatar
    Community Member
    288 Posts

    Re: Files uploaded via FTP vs CMS Link to this post

    Setup a custom controller action that runs the check for new files function and then call that periodically with a cron script. Since all files ss recognizes have to be either the file class or a subclass thereof a script needs to run to check.

  • Rod
    Avatar
    Community Member
    12 Posts

    Re: Files uploaded via FTP vs CMS Link to this post

    Thanks Smurkas. That sounds like it would work..... I don't suppose you could post some sample code??

    Thanks
    Liam

  • Rod
    Avatar
    Community Member
    12 Posts

    Re: Files uploaded via FTP vs CMS Link to this post

    I solved this problem.

    Within Page.php's controller:

    public function FileSync() {
       return FileSystem::sync();
    }

    Then within the template (actually, within an include used on just one page):

    <% control FileSync %><% end_control %>

    It unfortunately has a noticeable impact on page speed (a couple of extra seconds), but otherwise works really well. As the speed issue only affects this page, it's probably worth it, as it ensures the list of files is always up to date.

    If anyone has any suggestions for improvement, please let me know!

    Cheers
    Liam

  • martimiz
    Avatar
    Forum Moderator
    1035 Posts

    Re: Files uploaded via FTP vs CMS Link to this post

    You could take a look at partial caching - limit execution of the sync operation to once every xx minutes...

    Or even write away a timestamp, to only perform the operation once a certain amount of time has passed

    I think cron would be the better option though

    858 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.