/** * Index DB by ajax call */ public function reindexStep() { $limit = self::INDEX_STEP; $page = (int) $this->app->jbrequest->get('page', 0); $offset = $limit * $page; $modelIndex = JBModelSearchindex::model(); $lines = $modelIndex->reIndex($limit, $offset); $total = $modelIndex->getTotal(); $current = $limit * ($page + 1); if ($current > $total) { $current = $total; } $progress = round($current * 100 / $total, 2); $this->app->jbajax->send(array('progress' => $progress, 'current' => $current, 'total' => $total, 'lines' => $lines, 'step' => $page + 1, 'stepsize' => $limit)); }
/** * Execute method of command * * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { $this->_executePrepare($input, $output); $this->_init(); // init vars $indexModel = \JBModelSearchindex::model(); $tolalItems = $indexModel->getTotal(); $indexStep = $this->_config->find('step', 100); $this->_showProfiler('Reindex - prepared'); $this->_progressBar('Database ReIndex', $tolalItems, $indexStep, function ($offset) use($indexModel, $indexStep) { $reIndex = $indexModel->reIndex($indexStep, $offset); return $reIndex < 0 ? false : true; }); $this->_showProfiler('Reindex - Done!'); }
/** * On item deleted event * @static * @param $event AppEvent */ public static function deleted($event) { // vars $app = self::app(); $item = $event->getSubject(); $itemType = $item->getType()->id; // check index table $tableName = $app->jbtables->getIndexTable($itemType); if (!$app->jbtables->isTableExists($tableName)) { $app->jbtables->createIndexTable($itemType); } // update index data JBModelSearchindex::model()->removeById($item); // execute item trigger $jbimageElements = $item->getElements(); foreach ($jbimageElements as $element) { if (method_exists($element, 'triggerItemDeleted')) { $element->triggerItemDeleted(); } } }
/** * @return string */ public function getInput() { JBModelSku::model(); $elements = array(); $app = App::getInstance('zoo'); $application = $app->zoo->getApplication(); $i = 0; $elementsList = $app->jbentity->getItemTypesData(1); $typesList = $app->jbtype->getSimpleList(); $exclude = JBModelSearchindex::model()->getExcludeTypes(); $textHeadType = JText::_('JBZOO_FIELDS_CORE'); $stdFields = array('' => JText::_('JBZOO_MODITEM_SELECT_OPTION'), '_itemauthor' => 'Item Author', '_itemcategory' => 'Item Category', '_itemcreated' => 'Item Created', '_itemfrontpage' => 'Item Frontpage', '_itemmodified' => 'Item Modified', '_itemname' => 'Item Name', '_itempublish_up' => 'Item Publish Up', '_itempublish_down' => 'Item Publish Down', '_itemtag' => 'Item Tag'); $elements[$textHeadType] = array('items' => $stdFields); foreach ($exclude as $key => $value) { if ($value == 'textarea') { unset($exclude[$key]); } } foreach ($elementsList as $type => $tmpElements) { if (array_key_exists($type, $typesList)) { $appType = $application->getType($type); if (!$appType) { continue; } foreach ($tmpElements as $key => $element) { if (!in_array($element['type'], $exclude) && strpos($key, '_') === false) { $instance = $appType->getElement($key); if ($instance instanceof ElementJBPrice) { $name = $instance->config->get('name'); $newEls[] = array('value' => $key, 'text' => '- ' . $name, 'disable' => true); if ($params = $instance->getElements()) { foreach ($params as $id => $param) { if ($param->hasFilterValue()) { $newEls[] = array('value' => $key . '__' . $id, 'text' => '-- ' . $name . ' - ' . $param->getName()); } } } } else { $newEls[$element['name']] = array('value' => $key, 'text' => $element['name']); } } } } if (!empty($newEls)) { $elements[$typesList[$type]] = array('items' => $newEls); } unset($newEls); } if (empty($this->value)) { $this->value = array(array('key' => '', 'value' => '')); } foreach ($this->value as $value) { $value = (array) $value; if ($i != 0 && (!isset($value['key']) || empty($value['key']))) { continue; } $html[] = '<div class="jbjkeyvalue-row">'; $html[] = JHtml::_('select.groupedlist', $elements, $this->getName($this->fieldname) . '[' . $i . '][key]', array('list.select' => isset($value['key']) ? $value['key'] : '')); $html[] = '<input ' . $app->jbhtml->buildAttrs(array('placeholder' => JText::_('JBZOO_JBKEYVALUE_VALUE'), 'type' => 'text', 'name' => $this->getName($this->fieldname) . '[' . $i . '][value]', 'value' => isset($value['value']) ? $value['value'] : '', 'class' => isset($class) ? $class : '')) . ' />'; if ($i !== 0) { $html[] = '<a href="#jbjkeyvalue-rem" class="jsJKeyValueRemove" title="' . JText::_('JBZOO_JBKEYVALUE_ADD') . '"></a>'; } $html[] = JBZOO_CLR; $html[] = '</div>'; $i++; } $html[] = JBZOO_CLR; $html[] = '<a href="#jbjkeyvalue-add" class="jsJKeyValueAdd">' . JText::_('JBZOO_JBKEYVALUE_ADD') . '</a>'; $html[] = JBZOO_CLR; return '<div class="jsJKeyValue">' . implode(PHP_EOL, $html) . '</div>' . JBZOO_CLR; }
/** * Get pre-prepared options list for itemorder list * @param int $index * @param string $prefix * @return array */ public function getSortElementsOptionList($index = 0, $prefix = '_jbzoo_<INDEX>') { $stdFields = array('corename', 'corealias', 'corecreated', 'corehits', 'coremodified', 'corepublish_down', 'corepublish_up', 'coreauthor'); if ($prefix) { $prefix = str_replace('<INDEX>', $index, $prefix) . '_field_'; } $excludeType = JBModelSearchindex::model()->getExcludeTypes(); $typesPath = $this->app->path->path('jbtypes:'); $files = JFolder::files($typesPath, '.config'); $app = $this->app->zoo->getApplication(); // add std fields $coreGrp = JText::_('JBZOO_FIELDS_CORE'); $options = array($coreGrp => array($prefix . '_none' => JText::_('JBZOO_FIELDS_CORE_NONE'), 'random' => JText::_('JBZOO_SORT_ORDER_RANDOM'))); foreach ($stdFields as $stdField) { $options[$coreGrp][] = $this->_createOption($prefix . $stdField, 'JBZOO_FIELDS_CORE_' . $stdField); } // add custom fields foreach ($files as $file) { $fileContent = $this->app->jbfile->read($typesPath . '/' . $file); $typeData = json_decode($fileContent, true); $elements = array(); if (!empty($typeData['elements'])) { foreach ($typeData['elements'] as $elementId => $element) { if (strpos($elementId, '_') === 0 || in_array($element['type'], $excludeType, true)) { continue; } if ($app) { if ($type = $app->getType(JFile::stripExt($file))) { $_element = $type->getElement($elementId); if ($_element instanceof ElementJBPrice) { $elements = array_merge($elements, $this->_getSortJBPriceOptionList($_element, $prefix)); } else { $elements[] = $this->_createOption($prefix . $elementId, $element['name'], false); } } } } } $options[$typeData['name']] = $elements; } return $options; }
/** * Add indexes and fields to table * @param $tableName * @param array $fields * @param $itemType */ public function _addFields($tableName, array $fields, $itemType) { if (empty($fields)) { return; } $indexModel = JBModelSearchindex::model(); $stdIndexFields = $indexModel->getStdIndexFields(); $excludedIndexTypes = $indexModel->getExcludeTypes(); $elements = $this->_getCurrentTypeElements($itemType); $types = array('s', 'n', 'd'); $currentIndexes = $this->getIndexes($tableName); $currentFields = $this->getFields($tableName, true); $indexCount = count($currentIndexes); $add = array(); foreach ($fields as $field) { if (strpos($field, '_') === 0 && !in_array($field, $stdIndexFields, true) || in_array($elements[$field]['type'], $excludedIndexTypes, true)) { continue; } foreach ($types as $type) { $filedName = $this->getFieldName($field, $type); if (!in_array($filedName, $currentFields, true)) { if ($type == 's') { $add[] = 'ADD COLUMN `' . $filedName . '` VARCHAR(50) NULL DEFAULT NULL COLLATE \'utf8_general_ci\''; } if ($type == 'n') { $add[] = 'ADD COLUMN `' . $filedName . '` DOUBLE NOT NULL DEFAULT \'0\''; } if ($type == 'd') { $add[] = 'ADD COLUMN `' . $filedName . '` DATETIME NULL DEFAULT NULL'; } } if (!in_array($filedName, $currentIndexes, true) && $indexCount < 63) { $indexCount++; $add[] = 'ADD INDEX `' . $filedName . '` (`' . $filedName . '`)'; } } } if (!empty($add)) { $sql = 'ALTER TABLE `' . $tableName . "`\n " . implode(",\n ", $add); $this->_query($sql); } }