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

Creating the add-on Show Deleted

Discussion in 'XenForo Development Discussions' started by AndyB, Sep 29, 2013.

  1. AndyB

    AndyB Well-Known Member

    Description:

    When a user deletes a post or thread, that is called a soft delete. This allows the administrator to review the soft deleted item to determine if it needs to be restored or physically deleted.

    This add-on was created to quickly display soft deleted posts and threads.

    Here's an example of what is shown:

    pic001.jpg
    Requirements:

    This add-on only works on XenForo v1.2 and above.

    Operation:

    To use this add-on you will want to type into your browser the following URL:

    http://www.site.com/forums/showdeleted/

    I recommend making a bookmark in your browser.

    Note:

    You can download this add-on from the Resources here:

    http://xenforo.com/community/resources/show-deleted.2387/
     
    Last edited: Oct 2, 2013
    Pereira, Marcus, nrep and 1 other person like this.
  2. AndyB

    AndyB Well-Known Member

    This tutorial will show the steps required to create this add-on.

    1) Create the directory structure
    2) Create the New Route Prefix
    3) Create the ShowDeleted.php file #1
    4) Create the ShowDeleted.php file #2
    5) Create the Code Event Listener
    6) Create the Listener.php file
    7) Create the DeletionLog.php file
    8) Create the andy_showdeleted template
     
    Amaury likes this.
  3. AndyB

    AndyB Well-Known Member

    Create the directory structure:

    library
    --Andy
    ----ShowDeleted
    ------ControllerPublic
    --------ShowDeleted.php
    ----Listener.php
    ----Model
    ------DeletionLog.php
    ----Route
    ------Prefix
    --------ShowDeleted.php
     
    Amaury likes this.
  4. AndyB

    AndyB Well-Known Member

    Create the New Route Prefix:

    This is required so the new route /showdeleted/ will call a PHP file.

    pic002.jpg
     
    Amaury likes this.
  5. AndyB

    AndyB Well-Known Member

    Create the ShowDeleted.php file #1:

    libarary/Andy/ShowDeleted/Route/Prefix/ShowDeleted.php

    PHP:
    <?php

    class Andy_ShowDeleted_Route_Prefix_ShowDeleted implements XenForo_Route_Interface
    {
        public function 
    match($routePathZend_Controller_Request_Http $requestXenForo_Router $router)
        {
            return 
    $router->getRouteMatch('Andy_ShowDeleted_ControllerPublic_ShowDeleted'$routePath);
        }
    }

    ?>
     
    Amaury likes this.
  6. AndyB

    AndyB Well-Known Member

    Create the ShowDeleted.php file #2:

    library/Andy/ShowDeleted/ControllerPublic/ShowDeleted.php

    PHP:
    <?php

    class Andy_ShowDeleted_ControllerPublic_ShowDeleted extends XenForo_ControllerPublic_Abstract
    {    
        protected function 
    _preDispatch($action)
        {
            if (!
    XenForo_Visitor::getInstance()->isSuperAdmin())
            {
                throw 
    $this->getNoPermissionResponseException();
            }
        } 
        
        public function 
    actionIndex()
        {                
            
    //########################################
            // get data
            
            // this is fetching $posts from XenForo_Model_DeletionLog 
            // the function getDeletedPosts() is initially not there
            // we extended XenForo_Model_DeletionLog with Andy_ShowDeleted_Model_DeletionLog
            // all Andy_ShowDeleted_Model_DeletionLog functions are now accessible from XenForo_Model_DeletionLog        
            
            // get deleted post_id numbers    
            
    $posts $this->getModelFromCache('XenForo_Model_DeletionLog')->getDeletedPosts();
            
            
    // this is fetching $threads from XenForo_Model_DeletionLog 
            // the function getDeletedThreads() is initially not there
            // we extended XenForo_Model_DeletionLog with Andy_ShowDeleted_Model_DeletionLog
            // all Andy_ShowDeleted_Model_DeletionLog functions are now accessible from XenForo_Model_DeletionLog

            // get deleted thread_id numbers
            
    $threads $this->getModelFromCache('XenForo_Model_DeletionLog')->getDeletedThreads();
                    
            
    //########################################
            // display data        
            
            // $viewParams must be an array
            
    $viewParams = array('posts' => $posts,'threads' => $threads,
            ); 
            
            
    // send to template for display
            
    return $this->responseView('Andy_ShowDeleted_ViewPublic_ShowDeleted''andy_showdeleted'$viewParams);
        }
    }

    ?>
     
    Amaury likes this.
  7. AndyB

    AndyB Well-Known Member

    The above ShowDeleted.php file gets its data from the class XenForo_Model_DeletionLog, which is located in the library/Xenforo/Model/DeletionLog.php file. It needed to be extended because the functions we needed were not there.

    How to extend the XenForo_Model_DeletionLog is shown in the following three posts.
     
    Amaury likes this.
  8. AndyB

    AndyB Well-Known Member

    Create the Code Event Listener:

    pic003.jpg
     
    Amaury likes this.
  9. AndyB

    AndyB Well-Known Member

    Create the Listener.php file:

    PHP:
    <?php

    class Andy_ShowDeleted_Listener
    {
        public static function 
    loadClassModel($class, array &$extend)
        {
            
    $extend[] = 'Andy_ShowDeleted_Model_DeletionLog';
        }
    }

    ?>
     
    Amaury likes this.
  10. AndyB

    AndyB Well-Known Member

    Create the DeletionLog.php file:

    PHP:
    <?php

    class Andy_ShowDeleted_Model_DeletionLog extends XFCP_Andy_ShowDeleted_Model_DeletionLog
    {
        public function 
    getDeletedPosts()
        {
            return 
    $this->_getDb()->fetchAll('
            SELECT content_id AS post_id, delete_username, xf_node.title, delete_reason
            FROM xf_deletion_log
            INNER JOIN xf_post ON xf_post.post_id = xf_deletion_log.content_id
            INNER JOIN xf_thread ON xf_thread.thread_id = xf_post.thread_id
            INNER JOIN xf_node ON xf_node.node_id = xf_thread.node_id
            WHERE content_type = "post"
            ORDER BY content_id DESC
            LIMIT 50'
    );
        }
        
        public function 
    getDeletedThreads()
        {
            return 
    $this->_getDb()->fetchAll('
            SELECT content_id AS thread_id, delete_username, xf_node.title, delete_reason
            FROM xf_deletion_log
            INNER JOIN xf_thread ON xf_thread.thread_id = xf_deletion_log.content_id
            INNER JOIN xf_node ON xf_node.node_id = xf_thread.node_id
            WHERE content_type = "thread"
            ORDER BY content_id DESC
            LIMIT 50'
    );
        }    
    }

    ?>
     
    Amaury likes this.
  11. AndyB

    AndyB Well-Known Member

    Create the andy_showdeleted template:

    Code:
    Soft deleted posts and threads - Maximum 100 shown
    
    <br /><br />
    
    <table class="dataTable">
    <tr class="dataRow">
    <th>Number</th>
    <th>Deleted By</th>
    <th>Forum</th>
    <th>Delete Reason</th>
    </tr>
    
    <xen:foreach loop="$posts" value="$post">
    <tr class="dataRow">
    <td><a href="{xen:link posts, $post}" />Post {$post.post_id}</a></td><td>{$post.delete_username}</td><td>{$post.title}</td><td>{$post.delete_reason}</td>
    </tr>
    </xen:foreach>
    
    <xen:foreach loop="$threads" value="$thread">
    <tr class="dataRow">
    <td><a href="{xen:link 'threads',  $thread}" />Thread {$thread.thread_id}</a></td><td>{$thread.delete_username}</td><td>{$thread.title}</td><td>{$thread.delete_reason}</td>
    </tr>
    </xen:foreach>
    </table>
    
     
    Last edited: Sep 29, 2013
    Amaury likes this.
  12. AndyB

    AndyB Well-Known Member

    The Add-on is now complete:

    Enjoy...
     
    Last edited: Oct 2, 2013
    Amaury and borbole like this.
  13. borbole

    borbole Well-Known Member

    You are on a roll, Keep up the good work :)
     
    nrep, Amaury and AndyB like this.
  14. Pereira

    Pereira Well-Known Member

    Many thanks for creating these. ;)
     
  15. DFI

    DFI Active Member

  16. AndyB

    AndyB Well-Known Member

    Admin only.
     
    DFI likes this.

Share This Page