10378 Posts in 2194 Topics by 1710 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 927 Views |
-
Tracking downloads with secure files module

23 December 2010 at 4:52am
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'); -
Re: Tracking downloads with secure files module

23 December 2010 at 4:55am
Removing the line 170: ob_flush(); from SecureFileController.php seems to solve this issue.
-
Re: Tracking downloads with secure files module

24 December 2010 at 7:58am
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.
-
Re: Tracking downloads with secure files module

24 December 2010 at 9:21am
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
-
Re: Tracking downloads with secure files module

6 January 2011 at 10:23pm
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.
| 927 Views | ||
|
Page:
1
|
Go to Top |


