<?xml version="1.0" encoding="UTF-8"?>
<plugin name="Bind Attachments to Post Author" version_long="10001" version_human="1.0.1" author="Roman Piminov" website="https://ramzes.blog/" update_check="https://ramzes.blog/files/ipb/bindattachmentstopostauthor/update.json"><hooks/><tasks><task key="bindattachmentstopostauthor" frequency="P0Y0M1DT0H0M0S"><![CDATA[<?php
/**
 * @brief       bindattachmentstopostauthor Task
 * @author      <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
 * @copyright   (c) 2001 - 2016 Invision Power Services, Inc.
 * @license     http://www.invisionpower.com/legal/standards/
 * @package     IPS Community Suite
 * @subpackage  bindattachmentstopostauthor
 * @since       08 Jan 2017
 * @version     SVN_VERSION_NUMBER
 */

namespace IPS\pluginTasks;

/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
    header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
    exit;
}

/**
 * bindattachmentstopostauthor Task
 */
class _bindattachmentstopostauthor extends \IPS\Task
{
    /**
     * Execute
     *
     * If ran successfully, should return anything worth logging. Only log something
     * worth mentioning (don't log "task ran successfully"). Return NULL (actual NULL, not '' or 0) to not log (which will be most cases).
     * If an error occurs which means the task could not finish running, throw an \IPS\Task\Exception - do not log an error as a normal log.
     * Tasks should execute within the time of a normal HTTP request.
     *
     * @return  mixed   Message to log or NULL
     * @throws  \IPS\Task\Exception
     */
    public function execute()
    {
        $db = \IPS\Db::i();

        $table_attachments = $db->prefix . 'core_attachments';
        $table_maps = $db->prefix . 'core_attachments_map';
        $table_posts = $db->prefix . 'forums_posts';

        $sql =
            "UPDATE $table_attachments a" .
                " LEFT JOIN $table_maps m" .
                    " ON m.attachment_id = a.attach_id" .
                " LEFT JOIN $table_posts p" .
                    " ON p.pid = m.id2" .
                " SET a.attach_member_id = p.author_id" .
                " WHERE" .
                    " p.author_id > 0" .
                    " AND a.attach_member_id != p.author_id" .
                    " AND m.location_key = 'forums_Forums'";

        $db->query($sql);

        return NULL;
    }

    /**
     * Cleanup
     *
     * If your task takes longer than 15 minutes to run, this method
     * will be called before execute(). Use it to clean up anything which
     * may not have been done
     *
     * @return  void
     */
    public function cleanup()
    {

    }
}]]></task></tasks><widgets/><htmlFiles/><cssFiles/><jsFiles/><resourcesFiles/><lang/><versions><version long="10001" human="1.0.1"><![CDATA[//<?php


/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
	header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
	exit;
}

/**
 * 1.0.1 Upgrade Code
 */
class ips_plugins_setup_upg_10001
{
	/**
	 * ...
	 *
	 * @return	array	If returns TRUE, upgrader will proceed to next step. If it returns any other value, it will set this as the value of the 'extra' GET parameter and rerun this step (useful for loops)
	 */
	public function step1()
	{
		

		return TRUE;
	}
	
	// You can create as many additional methods (step2, step3, etc.) as is necessary.
	// Each step will be executed in a new HTTP request
}]]></version></versions></plugin>
