Jump to:

10928 Posts in 2612 Topics by 1809 members

All other Modules

SilverStripe Forums » All other Modules » Tracking downloads with secure files module

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 1142 Views
  • MarijnKampf
    Avatar
    Community Member
    164 Posts

    Tracking downloads with secure files module Link to this post

    I'm trying to track which files are downloaded by particular users. In my code I extended the function onAccessGranted() from the Secure Files Module. However, with some files I'm getting a File not found error. Live HTTP Headers shows:

    HTTP/1.1 500 Notice: "ob_flush() [<a href='ref.outcontrol'>ref.outcontrol</a>]: failed to flush buffer. No buffer to flush." at line 170 of G:\localhost\4ddynamics.eu\securefiles\code\SecureFileController.php

    Below the code I'm using. Is it an error in the SecureFileController.php or is it my code?

    TrackDownload.php

    <?php
    class TrackDownload extends DataObjectDecorator {
    function extraStatics() {
          return array(
             'many_many' => array(
                'Members' => 'Member' // Downloaders
             )
          );
    // Return an array containing keys 'db', 'has_one', 'many_many', 'belongs_many_many',
    }

       public function onAccessGranted() {
          $member = Member::currentUser();
          $this->owner->Members()->add($member);
          $this->owner->Members()->write();
          //Debug::Show("Access Granted");
       }

       public function onAccessDenied() {
    //      Debug::Show("Access Denied");
    //      exit();
       }

       public function summaryFields() {
          return array(
             'Members' => 'User'
          );
       }

       public function getCMSFields() {
          $fields = parent::getCMSFields();
       $this->extend('updateCMSFields', $fields);
       return $fields;
       }

       public function updateCMSFields(FieldSet $fields) {
       // DataObject::get("Product", "", "Title ASC")->toDropdownMap()
    //      $fields->addFieldToTab("Root.Downloaders", new CheckboxSetField('Members','Downloaders', $this->Members));
       }
    }

    User.php

    <?php
    class User extends DataObjectDecorator {
    function extraStatics() {
          return array(
             'db' => array(
                'Company' => 'Varchar(255)',
                'Country' => 'Varchar(255)',
                'Marketing' => 'Boolean',
             ),
             'many_many' => array(
                'Products' => 'Product',
             ),
             'belongs_many_many' => array(
                'Downloaded' => 'File'
             )
          );
    // Return an array containing keys 'db', 'has_one', 'many_many', 'belongs_many_many',
    }

    function somethingElse() {
    // You can add any other methods you like, which you can call directly on the member object.
    }

       public function getCMSFields() {
          $fields = parent::getCMSFields();
       $this->extend('updateCMSFields', $fields);
       return $fields;
       }

       public function updateCMSFields(FieldSet $fields) {
    $fields->addFieldToTab("Root.Main", new TextField('Company', 'Company'), "MemberUserDetailsHeader");
    $fields->addFieldToTab("Root.Main", new TextField('Country', 'Country'), "MemberUserDetailsHeader");

          $fields->addFieldToTab("Root.Products", new CheckboxSetField('Products','Interested in products (check all that apply)', DataObject::get("Product", "", "Title ASC")->toDropdownMap()));
       }
    }

    _config.php

    DataObject::add_extension('Member', 'User');
    DataObject::add_extension('File', 'TrackDownload');

  • MarijnKampf
    Avatar
    Community Member
    164 Posts

    Re: Tracking downloads with secure files module Link to this post

    Removing the line 170: ob_flush(); from SecureFileController.php seems to solve this issue.

  • MarijnKampf
    Avatar
    Community Member
    164 Posts

    Re: Tracking downloads with secure files module Link to this post

    Another issue I came across is using the above code I get a 'ugly' HTTP Error 403 (Forbidden) error when users are logged into the system, but do not have group permission to access a file. (Using group permissions). If they aren't logged in they get a 'pretty' error with login form.

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Tracking downloads with secure files module Link to this post

    With ob_flush() it should be safe to suppress errors (@)... not quite sure exactly what is causing the error - usually other server modules are doing something else with the output buffer so they might not work 'as expected' but can still be safely called.

    Could you log the issues you've had at http://redmine.polemic.net.nz/projects/secure-files and I can take a look when I'm back from holiday

  • MarijnKampf
    Avatar
    Community Member
    164 Posts

    Re: Tracking downloads with secure files module Link to this post

    Requested an account on your Redmine site, please ignore the second account as I didn't notice that the account had to be manually approved first.

    1142 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.