Back to FinderIndexCommand class

Method putFilters

private void
putFilters
()
Restore static filters.
Returns
  • void
Since
  • 3.3

Method putFilters - Source code

/**
 * Restore static filters.
 *
 * Using the saved filter information, update the filter records
 * with the new taxonomy ids.
 *
 * @return  void
 *
 * @since   3.3
 */
private function putFilters()
{
    $this->ioStyle->text(Text::_('FINDER_CLI_RESTORE_FILTERS'));
    $db = $this->db;
    // Use the temporary filter information to update the filter taxonomy ids.
    foreach ($this->filters as $filter_id => $filter) {
        $tids = array();
        foreach ($filter as $element) {
            // Look for the old taxonomy in the new taxonomy table.
            $query = $db->getQuery(true);
            $query->select('t.id')->from($db->quoteName('#__finder_taxonomy') . ' AS t')->leftJoin($db->quoteName('#__finder_taxonomy') . ' AS p ON p.id = t.parent_id')->where($db->quoteName('t.title') . ' = ' . $db->quote($element['title']))->where($db->quoteName('p.title') . ' = ' . $db->quote($element['parent']));
            $taxonomy = $db->setQuery($query)->loadResult();
            // If we found it then add it to the list.
            if ($taxonomy) {
                $tids[] = $taxonomy;
            } else {
                $text = Text::sprintf('FINDER_CLI_FILTER_RESTORE_WARNING', $element['parent'], $element['title'], $element['filter']);
                $this->ioStyle->text($text);
            }
        }
        // Construct a comma-separated string from the taxonomy ids.
        $taxonomyIds = empty($tids) ? '' : implode(',', $tids);
        // Update the filter with the new taxonomy ids.
        $query = $db->getQuery(true);
        $query->update($db->quoteName('#__finder_filters'))->set($db->quoteName('data') . ' = ' . $db->quote($taxonomyIds))->where($db->quoteName('filter_id') . ' = ' . (int) $filter_id);
        $db->setQuery($query)->execute();
    }
    $this->ioStyle->text(Text::sprintf('FINDER_CLI_RESTORE_FILTER_COMPLETED', count($this->filters)));
}