-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ BUG ] Accessing $this->di in model causes connection reset #911
Comments
Could you please post the code that reproduces the bug? The less code, the better :-) |
Here's the model causing the problem. More code than is necessary, but I thought I'd give you context. If I remove the <?PHP
namespace App;
use \Phalcon\Mvc\Model\Message;
class File extends \Phalcon\Mvc\Model{
use \MessagesTrait;
/*
* All of the following functions are built-in functions called
* automagically at various points by Phalcon
*/
public function initialize(){
$this->belongsTo('id','App\Request','request_id',
[
'foreignKey'=> [
'action'=>\Phalcon\Mvc\Model\Relation::ACTION_CASCADE
]
]
);
}
# On create, moves the uploaded file from the upload to download directory
public function beforeCreate(){
$Config = \Phalcon\DI\FactoryDefault::getDefault()->getShared('config');
$uploaded_path = $Config->dir->upload_dir.$this->name_original;
$destination_path = $Config->dir->download_dir.$this->request_id.'/'.$this->name;
if(!$this->_validateFilePath($uploaded_path))
return FALSE;
if(!$this->type)
$this->determineType();
if(!$this->size)
$this->determineSize();
if(!$this->_moveFile($uploaded_path,$destination_path))
return FALSE;
return TRUE;
}
public function afterFetch(){
$Config = $this->di->getShared('config');
}
/*
*
* Helper functions called non-automatically
*
*/
private function _validateFilePath($path){
if($path !== realpath($path)){
$Message = new Message(
'The requested file ('.$path.') is not a valid uploaded file.',
'file'
);
$this->appendMessage($Message);
return FALSE;
}
else
return TRUE;
}
private function _moveFile($upload_path,$destination_path){
if(!@rename($upload_path,$destination_path)){
$this->appendMessage(new Message(
'Error while moving uploaded file to Request-specific directory.',
'file'
)
);
return FALSE;
}
return TRUE;
}
public function determineType(){
$Config = \Phalcon\DI\FactoryDefault::getDefault()->getShared('config');
$path = $Config->dir->upload_dir.$this->name_original;
$FI = new \finfo();
$this->type = $FI->file($path,FILEINFO_MIME_TYPE);
}
//use this function (found here: http://ca3.php.net/manual/en/function.filesize.php)
//rather than filesize(), because files may be larger than 2GB
// function also found in FTPFile
public function determineSize(){
$Config = \Phalcon\DI\FactoryDefault::getDefault()->getShared('config');
$path = $Config->dir->upload_dir.$this->name_original;
$this->size = \Lib::getFileSize($path);
}
public function getSize(){
return \Lib::filesizeFormatted($this->size);
}
} |
Sorry, I should have been more clear. What I need is the code I can run locally to reproduce the bug. If possible, could you please give me the URL of the repo that I can clone, run and see the crash? |
Sorry, no - my code isn't in a repo. However, as far as I can tell, this happens whenever I have afterFetch() call a method on |
One question: won't Is that correct? |
Could you please grab the latest 1.3.0 and check whether the bug is still there? |
Yes, $this->di is NULL. What I'm doing to trigger this problem is not proper code, so a properly built model won't encounter this problem. I brought it up though, because even improper code should cause an error, not a connection loss. I'll try to install 1.3.0... |
So I believe I cloned & installed the right branch with |
I just need to update the version for 1.3.0 Glad it has been resolved The contents of this message may contain confidential or privileged On Thu, Jul 25, 2013 at 3:26 PM, quasipickle notifications@github.comwrote:
|
I have a model with a function I'm calling from Volt. In that function, I call
$this->di->get('config')
. I realize now that's the wrong way to do it, but regardless, whenever that function is called, my connection to the server via my browser gets reset.I'm not sure how to get more information to attach to this report.
Edit It doesn't appear now that this problem is tied to Volt, but rather tied to accessing
$this->di
fromModel::afterFetch()
The text was updated successfully, but these errors were encountered: