• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Run Action after DW save

R

ragtek

Guest
#1
I'd like to run own code after the save action from XenForo_DataWriter_AddOn.
How can i do this?
 

dmnkhhn

Active member
#2
There is a _postSave() method you could use in your DataWriter. :)

More information:

There are certain methods for certain events. The _postSave() method in a DataWriter gets called after the saving process.

When you are extending a DataWriter, you can copy this method to your DataWriter to handle the stuff that needs to be done after the saving (updating counters etc.).

Take a look at library/XenForo/DataWriter/Attachment.php (line 82) - there is even a method to handle the stuff that needs to be done before the saving (_preSave()).


PHP:
// Example from library/XenForo/DataWriter/Attachment.php
	/**
	 * Post-save handling.
	 */
	protected function _postSave()
	{
		$this->_db->query('
			UPDATE xf_attachment_data
			SET attach_count = attach_count + 1
			WHERE data_id = ?
		', $this->get('data_id'));
	}
 
R

ragtek

Guest
#3
thx, working like a charm

PHP:
// todo move to own class instead of creating new methods here
class Ragtek_DeveloperTools_AddOn extends XFCP_Ragtek_DeveloperTools_AddOn
{
    private $addOnId = '';
    private $path = '';

    protected function _postSave()
    {
        if ($this->isInsert())
        {
            $this->_createFolders();
            $this->_createFiles();
        }
        parent::_postSave();

        // create folder
    }