Source for file adapter.php

Documentation is available at adapter.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_finder
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. JLoader::register('FinderIndexer'__DIR__ . '/indexer.php');
  13. JLoader::register('FinderIndexerHelper'__DIR__ . '/helper.php');
  14. JLoader::register('FinderIndexerResult'__DIR__ . '/result.php');
  15. JLoader::register('FinderIndexerTaxonomy'__DIR__ . '/taxonomy.php');
  16.  
  17. /**
  18.  * Prototype adapter class for the Finder indexer package.
  19.  *
  20.  * @package     Joomla.Administrator
  21.  * @subpackage  com_finder
  22.  * @since       2.5
  23.  */
  24. abstract class FinderIndexerAdapter extends JPlugin
  25. {
  26.     /**
  27.      * The context is somewhat arbitrary but it must be unique or there will be
  28.      * conflicts when managing plugin/indexer state. A good best practice is to
  29.      * use the plugin name suffix as the context. For example, if the plugin is
  30.      * named 'plgFinderContent', the context could be 'Content'.
  31.      *
  32.      * @var    string 
  33.      * @since  2.5
  34.      */
  35.     protected $context;
  36.  
  37.     /**
  38.      * The extension name.
  39.      *
  40.      * @var    string 
  41.      * @since  2.5
  42.      */
  43.     protected $extension;
  44.  
  45.     /**
  46.      * The sublayout to use when rendering the results.
  47.      *
  48.      * @var    string 
  49.      * @since  2.5
  50.      */
  51.     protected $layout;
  52.  
  53.     /**
  54.      * The mime type of the content the adapter indexes.
  55.      *
  56.      * @var    string 
  57.      * @since  2.5
  58.      */
  59.     protected $mime;
  60.  
  61.     /**
  62.      * The access level of an item before save.
  63.      *
  64.      * @var    integer 
  65.      * @since  2.5
  66.      */
  67.     protected $old_access;
  68.  
  69.     /**
  70.      * The access level of a category before save.
  71.      *
  72.      * @var    integer 
  73.      * @since  2.5
  74.      */
  75.     protected $old_cataccess;
  76.  
  77.     /**
  78.      * The type of content the adapter indexes.
  79.      *
  80.      * @var    string 
  81.      * @since  2.5
  82.      */
  83.     protected $type_title;
  84.  
  85.     /**
  86.      * The type id of the content.
  87.      *
  88.      * @var    integer 
  89.      * @since  2.5
  90.      */
  91.     protected $type_id;
  92.  
  93.     /**
  94.      * The database object.
  95.      *
  96.      * @var    object 
  97.      * @since  2.5
  98.      */
  99.     protected $db;
  100.  
  101.     /**
  102.      * The table name.
  103.      *
  104.      * @var    string 
  105.      * @since  2.5
  106.      */
  107.     protected $table;
  108.  
  109.     /**
  110.      * The indexer object.
  111.      *
  112.      * @var    FinderIndexer 
  113.      * @since  3.0
  114.      */
  115.     protected $indexer;
  116.  
  117.     /**
  118.      * The field the published state is stored in.
  119.      *
  120.      * @var    string 
  121.      * @since  2.5
  122.      */
  123.     protected $state_field = 'state';
  124.  
  125.     /**
  126.      * Method to instantiate the indexer adapter.
  127.      *
  128.      * @param   object  &$subject  The object to observe.
  129.      * @param   array   $config    An array that holds the plugin configuration.
  130.      *
  131.      * @since   2.5
  132.      */
  133.     public function __construct(&$subject$config)
  134.     {
  135.         // Get the database object.
  136.         $this->db = JFactory::getDbo();
  137.  
  138.         // Call the parent constructor.
  139.         parent::__construct($subject$config);
  140.  
  141.         // Get the type id.
  142.         $this->type_id = $this->getTypeId();
  143.  
  144.         // Add the content type if it doesn't exist and is set.
  145.         if (empty($this->type_id&& !empty($this->type_title))
  146.         {
  147.             $this->type_id = FinderIndexerHelper::addContentType($this->type_title$this->mime);
  148.         }
  149.  
  150.         // Check for a layout override.
  151.         if ($this->params->get('layout'))
  152.         {
  153.             $this->layout = $this->params->get('layout');
  154.         }
  155.  
  156.         // Get the indexer object
  157.         $this->indexer = FinderIndexer::getInstance();
  158.     }
  159.  
  160.     /**
  161.      * Method to get the adapter state and push it into the indexer.
  162.      *
  163.      * @return  boolean  True on success.
  164.      *
  165.      * @since   2.5
  166.      * @throws    Exception on error.
  167.      */
  168.     public function onStartIndex()
  169.     {
  170.  
  171.         // Get the indexer state.
  172.         $iState FinderIndexer::getState();
  173.  
  174.         // Get the number of content items.
  175.         $total = (int) $this->getContentCount();
  176.  
  177.         // Add the content count to the total number of items.
  178.         $iState->totalItems += $total;
  179.  
  180.         // Populate the indexer state information for the adapter.
  181.         $iState->pluginState[$this->context]['total'$total;
  182.         $iState->pluginState[$this->context]['offset'0;
  183.  
  184.         // Set the indexer state.
  185.         FinderIndexer::setState($iState);
  186.     }
  187.  
  188.     /**
  189.      * Method to prepare for the indexer to be run. This method will often
  190.      * be used to include dependencies and things of that nature.
  191.      *
  192.      * @return  boolean  True on success.
  193.      *
  194.      * @since   2.5
  195.      * @throws  Exception on error.
  196.      */
  197.     public function onBeforeIndex()
  198.     {
  199.         // Get the indexer and adapter state.
  200.         $iState FinderIndexer::getState();
  201.         $aState $iState->pluginState[$this->context];
  202.  
  203.         // Check the progress of the indexer and the adapter.
  204.         if ($iState->batchOffset == $iState->batchSize || $aState['offset'== $aState['total'])
  205.         {
  206.             return true;
  207.         }
  208.  
  209.         // Run the setup method.
  210.         return $this->setup();
  211.     }
  212.  
  213.     /**
  214.      * Method to index a batch of content items. This method can be called by
  215.      * the indexer many times throughout the indexing process depending on how
  216.      * much content is available for indexing. It is important to track the
  217.      * progress correctly so we can display it to the user.
  218.      *
  219.      * @return  boolean  True on success.
  220.      *
  221.      * @since   2.5
  222.      * @throws  Exception on error.
  223.      */
  224.     public function onBuildIndex()
  225.     {
  226.         // Get the indexer and adapter state.
  227.         $iState FinderIndexer::getState();
  228.         $aState $iState->pluginState[$this->context];
  229.  
  230.         // Check the progress of the indexer and the adapter.
  231.         if ($iState->batchOffset == $iState->batchSize || $aState['offset'== $aState['total'])
  232.         {
  233.             return true;
  234.         }
  235.  
  236.         // Get the batch offset and size.
  237.         $offset = (int) $aState['offset'];
  238.         $limit = (int) ($iState->batchSize $iState->batchOffset);
  239.  
  240.         // Get the content items to index.
  241.         $items $this->getItems($offset$limit);
  242.  
  243.         // Iterate through the items and index them.
  244.         for ($i 0$n count($items)$i $n$i++)
  245.         {
  246.             // Index the item.
  247.             $this->index($items[$i]);
  248.  
  249.             // Adjust the offsets.
  250.             $offset++;
  251.             $iState->batchOffset++;
  252.             $iState->totalItems--;
  253.         }
  254.  
  255.         // Update the indexer state.
  256.         $aState['offset'$offset;
  257.         $iState->pluginState[$this->context$aState;
  258.         FinderIndexer::setState($iState);
  259.  
  260.         return true;
  261.     }
  262.  
  263.     /**
  264.      * Method to change the value of a content item's property in the links
  265.      * table. This is used to synchronize published and access states that
  266.      * are changed when not editing an item directly.
  267.      *
  268.      * @param   string   $id        The ID of the item to change.
  269.      * @param   string   $property  The property that is being changed.
  270.      * @param   integer  $value     The new value of that property.
  271.      *
  272.      * @return  boolean  True on success.
  273.      *
  274.      * @since   2.5
  275.      * @throws    Exception on database error.
  276.      */
  277.     protected function change($id$property$value)
  278.     {
  279.         // Check for a property we know how to handle.
  280.         if ($property !== 'state' && $property !== 'access')
  281.         {
  282.             return true;
  283.         }
  284.  
  285.         // Get the url for the content id.
  286.         $item $this->db->quote($this->getUrl($id$this->extension$this->layout));
  287.  
  288.         // Update the content items.
  289.         $query $this->db->getQuery(true)
  290.             ->update($this->db->quoteName('#__finder_links'))
  291.             ->set($this->db->quoteName($property' = ' . (int) $value)
  292.             ->where($this->db->quoteName('url'' = ' $item);
  293.         $this->db->setQuery($query);
  294.         $this->db->execute();
  295.  
  296.         return true;
  297.     }
  298.  
  299.     /**
  300.      * Method to index an item.
  301.      *
  302.      * @param   FinderIndexerResult  $item  The item to index as a FinderIndexerResult object.
  303.      *
  304.      * @return  boolean  True on success.
  305.      *
  306.      * @since   2.5
  307.      * @throws  Exception on database error.
  308.      */
  309.     abstract protected function index(FinderIndexerResult $item);
  310.  
  311.     /**
  312.      * Method to reindex an item.
  313.      *
  314.      * @param   integer  $id  The ID of the item to reindex.
  315.      *
  316.      * @return  boolean  True on success.
  317.      *
  318.      * @since   2.5
  319.      * @throws  Exception on database error.
  320.      */
  321.     protected function reindex($id)
  322.     {
  323.         // Run the setup method.
  324.         $this->setup();
  325.  
  326.         // Get the item.
  327.         $item $this->getItem($id);
  328.  
  329.         // Index the item.
  330.         $this->index($item);
  331.     }
  332.  
  333.     /**
  334.      * Method to remove an item from the index.
  335.      *
  336.      * @param   string  $id  The ID of the item to remove.
  337.      *
  338.      * @return  boolean  True on success.
  339.      *
  340.      * @since   2.5
  341.      * @throws  Exception on database error.
  342.      */
  343.     protected function remove($id)
  344.     {
  345.         // Get the item's URL
  346.         $url $this->db->quote($this->getUrl($id$this->extension$this->layout));
  347.  
  348.         // Get the link ids for the content items.
  349.         $query $this->db->getQuery(true)
  350.             ->select($this->db->quoteName('link_id'))
  351.             ->from($this->db->quoteName('#__finder_links'))
  352.             ->where($this->db->quoteName('url'' = ' $url);
  353.         $this->db->setQuery($query);
  354.         $items $this->db->loadColumn();
  355.  
  356.         // Check the items.
  357.         if (empty($items))
  358.         {
  359.             return true;
  360.         }
  361.  
  362.         // Remove the items.
  363.         foreach ($items as $item)
  364.         {
  365.             $this->indexer->remove($item);
  366.         }
  367.  
  368.         return true;
  369.     }
  370.  
  371.     /**
  372.      * Method to setup the adapter before indexing.
  373.      *
  374.      * @return  boolean  True on success, false on failure.
  375.      *
  376.      * @since   2.5
  377.      * @throws  Exception on database error.
  378.      */
  379.     abstract protected function setup();
  380.  
  381.     /**
  382.      * Method to update index data on category access level changes
  383.      *
  384.      * @param   JTable  $row  A JTable object
  385.      *
  386.      * @return  void 
  387.      *
  388.      * @since   2.5
  389.      */
  390.     protected function categoryAccessChange($row)
  391.     {
  392.         $query clone($this->getStateQuery());
  393.         $query->where('c.id = ' . (int) $row->id);
  394.  
  395.         // Get the access level.
  396.         $this->db->setQuery($query);
  397.         $items $this->db->loadObjectList();
  398.  
  399.         // Adjust the access level for each item within the category.
  400.         foreach ($items as $item)
  401.         {
  402.             // Set the access level.
  403.             $temp max($item->access$row->access);
  404.  
  405.             // Update the item.
  406.             $this->change((int) $item->id'access'$temp);
  407.  
  408.             // Reindex the item
  409.             $this->reindex($row->id);
  410.         }
  411.     }
  412.  
  413.     /**
  414.      * Method to update index data on category access level changes
  415.      *
  416.      * @param   array    $pks    A list of primary key ids of the content that has changed state.
  417.      * @param   integer  $value  The value of the state that the content has been changed to.
  418.      *
  419.      * @return  void 
  420.      *
  421.      * @since   2.5
  422.      */
  423.     protected function categoryStateChange($pks$value)
  424.     {
  425.         /*
  426.          * The item's published state is tied to the category
  427.          * published state so we need to look up all published states
  428.          * before we change anything.
  429.          */
  430.         foreach ($pks as $pk)
  431.         {
  432.             $query clone($this->getStateQuery());
  433.             $query->where('c.id = ' . (int) $pk);
  434.  
  435.             // Get the published states.
  436.             $this->db->setQuery($query);
  437.             $items $this->db->loadObjectList();
  438.  
  439.             // Adjust the state for each item within the category.
  440.             foreach ($items as $item)
  441.             {
  442.                 // Translate the state.
  443.                 $temp $this->translateState($item->state$value);
  444.  
  445.                 // Update the item.
  446.                 $this->change($item->id'state'$temp);
  447.  
  448.                 // Reindex the item
  449.                 $this->reindex($item->id);
  450.             }
  451.         }
  452.     }
  453.  
  454.     /**
  455.      * Method to check the existing access level for categories
  456.      *
  457.      * @param   JTable  $row  A JTable object
  458.      *
  459.      * @return  void 
  460.      *
  461.      * @since   2.5
  462.      */
  463.     protected function checkCategoryAccess($row)
  464.     {
  465.         $query $this->db->getQuery(true)
  466.             ->select($this->db->quoteName('access'))
  467.             ->from($this->db->quoteName('#__categories'))
  468.             ->where($this->db->quoteName('id'' = ' . (int) $row->id);
  469.         $this->db->setQuery($query);
  470.  
  471.         // Store the access level to determine if it changes
  472.         $this->old_cataccess = $this->db->loadResult();
  473.     }
  474.  
  475.     /**
  476.      * Method to check the existing access level for items
  477.      *
  478.      * @param   JTable  $row  A JTable object
  479.      *
  480.      * @return  void 
  481.      *
  482.      * @since   2.5
  483.      */
  484.     protected function checkItemAccess($row)
  485.     {
  486.         $query $this->db->getQuery(true)
  487.             ->select($this->db->quoteName('access'))
  488.             ->from($this->db->quoteName($this->table))
  489.             ->where($this->db->quoteName('id'' = ' . (int) $row->id);
  490.         $this->db->setQuery($query);
  491.  
  492.         // Store the access level to determine if it changes
  493.         $this->old_access = $this->db->loadResult();
  494.     }
  495.  
  496.     /**
  497.      * Method to get the number of content items available to index.
  498.      *
  499.      * @return  integer  The number of content items available to index.
  500.      *
  501.      * @since   2.5
  502.      * @throws  Exception on database error.
  503.      */
  504.     protected function getContentCount()
  505.     {
  506.         $return 0;
  507.  
  508.         // Get the list query.
  509.         $query $this->getListQuery();
  510.  
  511.         // Check if the query is valid.
  512.         if (empty($query))
  513.         {
  514.             return $return;
  515.         }
  516.  
  517.         // Tweak the SQL query to make the total lookup faster.
  518.         if ($query instanceof JDatabaseQuery)
  519.         {
  520.             $query clone($query);
  521.             $query->clear('select')
  522.                 ->select('COUNT(*)')
  523.                 ->clear('order');
  524.         }
  525.  
  526.         // Get the total number of content items to index.
  527.         $this->db->setQuery($query);
  528.         $return = (int) $this->db->loadResult();
  529.  
  530.         return $return;
  531.     }
  532.  
  533.     /**
  534.      * Method to get a content item to index.
  535.      *
  536.      * @param   integer  $id  The id of the content item.
  537.      *
  538.      * @return  FinderIndexerResult  A FinderIndexerResult object.
  539.      *
  540.      * @since   2.5
  541.      * @throws  Exception on database error.
  542.      */
  543.     protected function getItem($id)
  544.     {
  545.         // Get the list query and add the extra WHERE clause.
  546.         $query $this->getListQuery();
  547.         $query->where('a.id = ' . (int) $id);
  548.  
  549.         // Get the item to index.
  550.         $this->db->setQuery($query);
  551.         $row $this->db->loadAssoc();
  552.  
  553.         // Convert the item to a result object.
  554.         $item JArrayHelper::toObject($row'FinderIndexerResult');
  555.  
  556.         // Set the item type.
  557.         $item->type_id $this->type_id;
  558.  
  559.         // Set the item layout.
  560.         $item->layout $this->layout;
  561.  
  562.         return $item;
  563.     }
  564.  
  565.     /**
  566.      * Method to get a list of content items to index.
  567.      *
  568.      * @param   integer         $offset  The list offset.
  569.      * @param   integer         $limit   The list limit.
  570.      * @param   JDatabaseQuery  $query   A JDatabaseQuery object. [optional]
  571.      *
  572.      * @return  array  An array of FinderIndexerResult objects.
  573.      *
  574.      * @since   2.5
  575.      * @throws  Exception on database error.
  576.      */
  577.     protected function getItems($offset$limit$query null)
  578.     {
  579.         $items array();
  580.  
  581.         // Get the content items to index.
  582.         $this->db->setQuery($this->getListQuery($query)$offset$limit);
  583.         $rows $this->db->loadAssocList();
  584.  
  585.         // Convert the items to result objects.
  586.         foreach ($rows as $row)
  587.         {
  588.             // Convert the item to a result object.
  589.             $item JArrayHelper::toObject($row'FinderIndexerResult');
  590.  
  591.             // Set the item type.
  592.             $item->type_id $this->type_id;
  593.  
  594.             // Set the mime type.
  595.             $item->mime $this->mime;
  596.  
  597.             // Set the item layout.
  598.             $item->layout $this->layout;
  599.  
  600.             // Set the extension if present
  601.             if (isset($row->extension))
  602.             {
  603.                 $item->extension $row->extension;
  604.             }
  605.  
  606.             // Add the item to the stack.
  607.             $items[$item;
  608.         }
  609.  
  610.         return $items;
  611.     }
  612.  
  613.     /**
  614.      * Method to get the SQL query used to retrieve the list of content items.
  615.      *
  616.      * @param   mixed  $query  A JDatabaseQuery object. [optional]
  617.      *
  618.      * @return  JDatabaseQuery  A database object.
  619.      *
  620.      * @since   2.5
  621.      */
  622.     protected function getListQuery($query null)
  623.     {
  624.         // Check if we can use the supplied SQL query.
  625.         $query $query instanceof JDatabaseQuery $query $this->db->getQuery(true);
  626.  
  627.         return $query;
  628.     }
  629.  
  630.     /**
  631.      * Method to get the plugin type
  632.      *
  633.      * @param   integer  $id  The plugin ID
  634.      *
  635.      * @return  string  The plugin type
  636.      *
  637.      * @since   2.5
  638.      */
  639.     protected function getPluginType($id)
  640.     {
  641.         // Prepare the query
  642.         $query $this->db->getQuery(true)
  643.             ->select($this->db->quoteName('element'))
  644.             ->from($this->db->quoteName('#__extensions'))
  645.             ->where($this->db->quoteName('extension_id'' = ' . (int) $id);
  646.         $this->db->setQuery($query);
  647.         $type $this->db->loadResult();
  648.  
  649.         return $type;
  650.     }
  651.  
  652.     /**
  653.      * Method to get a SQL query to load the published and access states for
  654.      * an article and category.
  655.      *
  656.      * @return  JDatabaseQuery  A database object.
  657.      *
  658.      * @since   2.5
  659.      */
  660.     protected function getStateQuery()
  661.     {
  662.         $query $this->db->getQuery(true);
  663.  
  664.         // Item ID
  665.         $query->select('a.id');
  666.  
  667.         // Item and category published state
  668.         $query->select('a.' $this->state_field . ' AS state, c.published AS cat_state');
  669.  
  670.         // Item and category access levels
  671.         $query->select('a.access, c.access AS cat_access')
  672.             ->from($this->table . ' AS a')
  673.             ->join('LEFT''#__categories AS c ON c.id = a.catid');
  674.  
  675.         return $query;
  676.     }
  677.  
  678.     /**
  679.      * Method to get the query clause for getting items to update by time.
  680.      *
  681.      * @param   string  $time  The modified timestamp.
  682.      *
  683.      * @return  JDatabaseQuery  A database object.
  684.      *
  685.      * @since   2.5
  686.      */
  687.     protected function getUpdateQueryByTime($time)
  688.     {
  689.         // Build an SQL query based on the modified time.
  690.         $query $this->db->getQuery(true)
  691.             ->where('a.modified >= ' $this->db->quote($time));
  692.  
  693.         return $query;
  694.     }
  695.  
  696.     /**
  697.      * Method to get the query clause for getting items to update by id.
  698.      *
  699.      * @param   array  $ids  The ids to load.
  700.      *
  701.      * @return  JDatabaseQuery  A database object.
  702.      *
  703.      * @since   2.5
  704.      */
  705.     protected function getUpdateQueryByIds($ids)
  706.     {
  707.         // Build an SQL query based on the item ids.
  708.         $query $this->db->getQuery(true)
  709.             ->where('a.id IN(' implode(','$ids')');
  710.  
  711.         return $query;
  712.     }
  713.  
  714.     /**
  715.      * Method to get the type id for the adapter content.
  716.      *
  717.      * @return  integer  The numeric type id for the content.
  718.      *
  719.      * @since   2.5
  720.      * @throws  Exception on database error.
  721.      */
  722.     protected function getTypeId()
  723.     {
  724.         // Get the type id from the database.
  725.         $query $this->db->getQuery(true)
  726.             ->select($this->db->quoteName('id'))
  727.             ->from($this->db->quoteName('#__finder_types'))
  728.             ->where($this->db->quoteName('title'' = ' $this->db->quote($this->type_title));
  729.         $this->db->setQuery($query);
  730.         $result = (int) $this->db->loadResult();
  731.  
  732.         return $result;
  733.     }
  734.  
  735.     /**
  736.      * Method to get the URL for the item. The URL is how we look up the link
  737.      * in the Finder index.
  738.      *
  739.      * @param   integer  $id         The id of the item.
  740.      * @param   string   $extension  The extension the category is in.
  741.      * @param   string   $view       The view for the URL.
  742.      *
  743.      * @return  string  The URL of the item.
  744.      *
  745.      * @since   2.5
  746.      */
  747.     protected function getURL($id$extension$view)
  748.     {
  749.         return 'index.php?option=' $extension '&view=' $view '&id=' $id;
  750.     }
  751.  
  752.     /**
  753.      * Method to get the page title of any menu item that is linked to the
  754.      * content item, if it exists and is set.
  755.      *
  756.      * @param   string  $url  The url of the item.
  757.      *
  758.      * @return  mixed  The title on success, null if not found.
  759.      *
  760.      * @since   2.5
  761.      * @throws  Exception on database error.
  762.      */
  763.     protected function getItemMenuTitle($url)
  764.     {
  765.         $return null;
  766.  
  767.         // Set variables
  768.         $user JFactory::getUser();
  769.         $groups implode(','$user->getAuthorisedViewLevels());
  770.  
  771.         // Build a query to get the menu params.
  772.         $query $this->db->getQuery(true)
  773.             ->select($this->db->quoteName('params'))
  774.             ->from($this->db->quoteName('#__menu'))
  775.             ->where($this->db->quoteName('link'' = ' $this->db->quote($url))
  776.             ->where($this->db->quoteName('published'' = 1')
  777.             ->where($this->db->quoteName('access'' IN (' $groups ')');
  778.  
  779.         // Get the menu params from the database.
  780.         $this->db->setQuery($query);
  781.         $params $this->db->loadResult();
  782.  
  783.         // Check the results.
  784.         if (empty($params))
  785.         {
  786.             return $return;
  787.         }
  788.  
  789.         // Instantiate the params.
  790.         $params json_decode($params);
  791.  
  792.         // Get the page title if it is set.
  793.         if ($params->page_title)
  794.         {
  795.             $return $params->page_title;
  796.         }
  797.  
  798.         return $return;
  799.     }
  800.  
  801.     /**
  802.      * Method to update index data on access level changes
  803.      *
  804.      * @param   JTable  $row  A JTable object
  805.      *
  806.      * @return  void 
  807.      *
  808.      * @since   2.5
  809.      */
  810.     protected function itemAccessChange($row)
  811.     {
  812.         $query clone($this->getStateQuery());
  813.         $query->where('a.id = ' . (int) $row->id);
  814.  
  815.         // Get the access level.
  816.         $this->db->setQuery($query);
  817.         $item $this->db->loadObject();
  818.  
  819.         // Set the access level.
  820.         $temp max($row->access$item->cat_access);
  821.  
  822.         // Update the item.
  823.         $this->change((int) $row->id'access'$temp);
  824.     }
  825.  
  826.     /**
  827.      * Method to update index data on published state changes
  828.      *
  829.      * @param   array    $pks    A list of primary key ids of the content that has changed state.
  830.      * @param   integer  $value  The value of the state that the content has been changed to.
  831.      *
  832.      * @return  void 
  833.      *
  834.      * @since   2.5
  835.      */
  836.     protected function itemStateChange($pks$value)
  837.     {
  838.         /*
  839.          * The item's published state is tied to the category
  840.          * published state so we need to look up all published states
  841.          * before we change anything.
  842.          */
  843.         foreach ($pks as $pk)
  844.         {
  845.             $query clone($this->getStateQuery());
  846.             $query->where('a.id = ' . (int) $pk);
  847.  
  848.             // Get the published states.
  849.             $this->db->setQuery($query);
  850.             $item $this->db->loadObject();
  851.  
  852.             // Translate the state.
  853.             $temp $this->translateState($value$item->cat_state);
  854.  
  855.             // Update the item.
  856.             $this->change($pk'state'$temp);
  857.  
  858.             // Reindex the item
  859.             $this->reindex($pk);
  860.         }
  861.     }
  862.  
  863.     /**
  864.      * Method to update index data when a plugin is disabled
  865.      *
  866.      * @param   array  $pks  A list of primary key ids of the content that has changed state.
  867.      *
  868.      * @return  void 
  869.      *
  870.      * @since   2.5
  871.      */
  872.     protected function pluginDisable($pks)
  873.     {
  874.         // Since multiple plugins may be disabled at a time, we need to check first
  875.         // that we're handling the appropriate one for the context
  876.         foreach ($pks as $pk)
  877.         {
  878.             if ($this->getPluginType($pk== strtolower($this->context))
  879.             {
  880.                 // Get all of the items to unindex them
  881.                 $query clone($this->getStateQuery());
  882.                 $this->db->setQuery($query);
  883.                 $items $this->db->loadColumn();
  884.  
  885.                 // Remove each item
  886.                 foreach ($items as $item)
  887.                 {
  888.                     $this->remove($item);
  889.                 }
  890.             }
  891.         }
  892.     }
  893.  
  894.     /**
  895.      * Method to translate the native content states into states that the
  896.      * indexer can use.
  897.      *
  898.      * @param   integer  $item      The item state.
  899.      * @param   integer  $category  The category state. [optional]
  900.      *
  901.      * @return  integer  The translated indexer state.
  902.      *
  903.      * @since   2.5
  904.      */
  905.     protected function translateState($item$category null)
  906.     {
  907.         // If category is present, factor in its states as well
  908.         if ($category !== null)
  909.         {
  910.             if ($category == 0)
  911.             {
  912.                 $item 0;
  913.             }
  914.         }
  915.  
  916.         // Translate the state
  917.         switch ($item)
  918.         {
  919.             // Published and archived items only should return a published state
  920.             case 1;
  921.             case 2:
  922.                 return 1;
  923.  
  924.             // All other states should return a unpublished state
  925.             default:
  926.             case 0:
  927.                 return 0;
  928.         }
  929.     }
  930. }

Documentation generated on Tue, 19 Nov 2013 14:53:24 +0100 by phpDocumentor 1.4.3