milesj / uploader

[Deprecated] A CakePHP plugin for file uploading and validating.
MIT License
193 stars 73 forks source link

Trouble with CakeDC Users Plugin #171

Closed DuncanLewis closed 10 years ago

DuncanLewis commented 10 years ago

Hey!

I've been having an issue attempting to use the uploader plugin with the CakeDC users plugin. I'm hoping to use the attachment behaviour to allow users to upload a personal profile image, but so far I haven't been able to get it to work correctly.

I've tried placing the attachment behaviour both in the User model, as well as the UserDetail model, however neither of these seem to be working. I'm not even sure if the behaviour is being called, let alone uploading the file.

There is no error output relating to the upload itself, only a MySQL error trying to insert a value of Array into the db. Clearly this error is caused by not inserting the name into the database, rather the entire image array. It's also worth noting that the file itself is not uploaded.

I'm currently trying to use the AWS functionality within the plugin. Here is my actAs:

public $actsAs = array(
        'Uploader.Attachment' => array(

            'UserDetail.avatar_file_name' => array(
                'overwrite' => true,
                'transport' => array(
                    'class' => AttachmentBehavior::S3,
                    'accessKey' => '************',
                    'secretKey' => '************',
                    'bucket' => 'piranhr',
                    'region' => Aws\Common\Enum\Region::EU_WEST_1,
                    'folder' => 'avatars/'
                )
            )
        ));

and my input:

    <?php echo $this->Form->input('UserDetail.avatar_file_name', array('type' => 'file')); ?>

Any insight you can provide would be great!

Thanks, Duncan

milesj commented 10 years ago

The behavior should be defined in the UserDetail model and the UserDetail.avatar_file_name in the array should simply be avatar_file_name.

DuncanLewis commented 10 years ago

Just tried your suggestions but still no luck. The upload isn't taking place, and it is still attempting to insert an array into the database field. Also theres no error being output from the uploader.

I can see that the Uploader plugin is being loaded for the model and action, but there aren't any errors relating to the plugin specifically.

Do you have anymore suggestions on this one?

Thanks for your time :)

milesj commented 10 years ago

Are you using the latest versions of everything? Does upload work outside of the users plugin?

DuncanLewis commented 10 years ago

Can confirm that it is working perfectly outside of the users plugin. Uploads to AWS from a different model save just fine, however on UserDetails still getting the error:

Array to string conversion [CORE/Cake/Model/Datasource/DboSource.php, line 1875]

Followed by an SQL error trying to insert Array.

Also can confirm I am on the latest versions of everything.

Any idea what might be causing this or do you think I am best just to put it in a separate model? Thanks for your help again :)

milesj commented 10 years ago

So I've never used the users plugin before. Where does UserDetail come from? Are there any before/after hooks defined in it?

DuncanLewis commented 10 years ago

The model user hasMany UserDetails. In the UserDetails table you have a column 'field', which contains, for example 'User.first_name' or 'User.avatar_file_name', there is then a 'value' obviously containing the actual value.

Now the editing of user details is actually done from within the users controller, not the UserDetails controller. The save is called through the users controller, and then calls an action called saveSection from the UserDetails model. Perhaps this is why the attachment behaviour isn't being triggered? Although it does eventually seem to call through to the standard save.

As for before/ after hooks I can't seem to see any unless I'm missing something.

milesj commented 10 years ago

Looks like you are using the 1.3 users plugin? I don't see the detail model in 2.0.

DuncanLewis commented 10 years ago

It appears I am on the deprecated/user-details version. I had no idea that they had changed this. It is still 2.0 however.

milesj commented 10 years ago

Well in the master branch there is no details model.

https://github.com/CakeDC/users/tree/master/Model

And no association.

https://github.com/CakeDC/users/blob/master/Model/User.php

In the deprecated branch, it looks like data is being remapped. It's probably breaking the upload process.

https://github.com/CakeDC/users/blob/deprecated/user-details/Model/UserDetail.php#L218

DuncanLewis commented 10 years ago

Yeah I figured that would be the issue. Will try and come up with some kind of solution / switch to master.

Thanks very much for your help! :)

milesj commented 10 years ago

I'd say just use the latest master branch, and then create your own details model. Should be the easiest approach.