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');