Getting back the attachment in a resource

CrispinP

Well-known member
hi folks,

Continuing on with my first add-on...

I have the following in my class (which works)
Code:
public function save()
    {       
        // call parent
        parent::save();   
       
       
        // get resourceId
        $resourceId = $this->get('resource_id');   

        //get the update id (just in case for now)
        $resourceUpdateId = $this->get('resource_update_id');

So far, so good.

however, when I try get the resource... I get nothing back.

Code:
$bla = $this->getModelFromCache('XenForo_Model_Attachment')->getAttachmentsByContentId('resource_update', $resourceId);

I have tried with both resourceid and resourceUpdateId

I'm using this http://fabrikar.com/forums/docs/classes/XenForo_Model_Attachment.html for guidance as well as digging through the other code. Is there a better way? :)

Am I on the right track to get the attachment out? and if so, why does my test return nothing?


TIA

Crispin
 
Give this code a try:

PHP:
$bla = $this->getModelFromCache('XenForo_Model_Attachment')->getAttachmentsByContentId('resource_update', $this->get('description_update_id'));

Can you please post the whole code that you are using btw?
 
Thanks for that. Why description update id? Where did you get that from? (trying to understand the structure)

That is my whole code :) only things omitted are the closing brackets. 3 hours and 3 lines :(

I'll give yours a try tomorrow.

Cheers,
Crispin
 
Well, couldn't sleep so why not wrestle with code...

Your suggestion did not work either. I now think that this is either being called in the wrong place or I am really not understanding it.

I suspect that I am making the call too soon. So far every method I have found in the core code (XenResource\ControllerPublic\Resource.php) needs version_id. Following this back to the DB call it uses whatver you passed in for the content_id field. This is the version_id.

Doing a var_dump in my add-on shows the version_id, current_version_id etc as being blank which makes me think I am calling it too early.

I have no hair left on my head :|
 
Folks,

I'm close to giving up here - I cannot for the life of me work out how to get the attachment for a resource when it has just been saved.

Of all the examples I have looked at in the core code and other add-ons the variables used for getting the attachments do not seem to match up with what I need. More so, they don't return any attachments.

What I have so far:
Code:
<?php

class Preview_DataWriter extends XFCP_Preview_DataWriter
{
    public function save()
    {       
        // call parent
        parent::save();   
       
       
        // get resourceId
        $resourceId = $this->get('resource_id');   

        //get the update id (just in case for now)
        $resourceUpdateId = $this->get('resource_update_id');   
       
        //get the update id (just in case for now)
        $descriptionUpdateId = $this->get('description_update_id');   
       
        //try this one       
        $resourceVersionId = $this->get('resource_version_id');   
       
               
        //print_r($this->_resource['is_fileless']);

        XenDebug_Log::getInstance()->log("resourceUpdateId = " . $resourceUpdateId, XenDebug_Log::TYPE_DEBUG, 3);
        XenDebug_Log::getInstance()->log("resource_id = " . $resourceId, XenDebug_Log::TYPE_DEBUG, 3);
        XenDebug_Log::getInstance()->log("descriptionUpdateId = " . $descriptionUpdateId, XenDebug_Log::TYPE_DEBUG, 3);
        XenDebug_Log::getInstance()->log("resourceVersionId= " . $resourceVersionId, XenDebug_Log::TYPE_DEBUG, 3);

       
        $bla = $this->getModelFromCache('XenForo_Model_Attachment')->getAttachmentsByContentId('resource_version', $resourceId);
        this is always an empty array.
var_dump($this);

//this always gives zero
        XenDebug_Log::getInstance()->log(count($bla), XenDebug_Log::TYPE_DEBUG, 3);
       
    }
}

While the resource_Ids show up the method returns an empty array.


Doing some further reading of the resource models I now think I need to get the versions from the model and once I have the versions then I can get the specific file. Can anyone confirm this is the correct thinking? And perhaps supply a few sample lines of code? :)


thanks
C
 
Back
Top Bottom