flush() 개인적인 메소드

Stellt alle Werte auf den Ursprungszustand zurueck.
private flush ( )
예제 #1
0
 /**
  * Indexes a certain column.
  * Returns the number of the indexed rows or false.
  * 
  * @param string $_table
  * @param mixed $_column
  * @param mixed $_idcol
  * @param mixed $_id
  * @param mixed $_start
  * @param mixed $_count
  * 
  * @return mixed
  */
 function indexColumn($_table, $_column, $_idcol = false, $_id = false, $_start = false, $_count = false, $_where = false)
 {
     $delete = new rex_sql();
     $where = sprintf(" `ftable` = '%s' AND `fcolumn` = '%s' AND `texttype` = 'db_column'", $delete->escape($_table), $delete->escape($_column));
     //if(is_string($_idcol) AND ($_id !== false))
     //$where .= sprintf(' AND fid = %d',$_id);
     // delete from cache
     $select = new rex_sql();
     $select->setTable($this->tablePrefix . '587_searchindex');
     $select->setWhere($where);
     $indexIds = array();
     if ($select->select('id')) {
         foreach ($select->getArray() as $result) {
             $indexIds[] = $result['id'];
         }
         $this->deleteCache($indexIds);
     }
     // delete old data
     if ($_start === 0) {
         $delete->setTable($this->tablePrefix . '587_searchindex');
         $delete->setWhere($where);
         $delete->delete();
     }
     $sql = new rex_sql();
     // get primary key column(s)
     $primaryKeys = array();
     foreach ($sql->getArray("SHOW COLUMNS FROM `" . $_table . "` WHERE `KEY` = 'PRI'") as $col) {
         $primaryKeys[] = $col['Field'];
     }
     // index column
     $sql->flush();
     $sql->setTable($_table);
     $where = '1 ';
     if (is_string($_idcol) and $_id) {
         $where .= sprintf(' AND (%s = %d)', $_idcol, $_id);
     }
     if (!empty($_where) and is_string($_where)) {
         $where .= ' AND (' . $_where . ')';
     }
     if (is_numeric($_start) and is_numeric($_count)) {
         $where .= ' LIMIT ' . $_start . ',' . $_count;
     }
     $sql->setWhere($where);
     $count = false;
     if ($sql->select('*')) {
         $this->beginFrontendMode();
         $count = 0;
         $keywords = array();
         foreach ($sql->getArray() as $value) {
             if (!empty($value[$_column]) and ($this->indexOffline or $this->tablePrefix . 'article' != $_table or $value['status'] == '1') and ($this->tablePrefix . 'article' != $_table or !in_array($value['id'], $this->excludeIDs))) {
                 $insert = new rex_sql();
                 $indexData = array();
                 $indexData['texttype'] = 'db_column';
                 $indexData['ftable'] = $_table;
                 $indexData['fcolumn'] = $_column;
                 if (array_key_exists('clang', $value)) {
                     $indexData['clang'] = $value['clang'];
                 } else {
                     $indexData['clang'] = NULL;
                 }
                 $indexData['fid'] = NULL;
                 if (is_string($_idcol) and array_key_exists($_idcol, $value)) {
                     $indexData['fid'] = $value[$_idcol];
                 } elseif ($_table == $this->tablePrefix . 'article') {
                     $indexData['fid'] = $value['id'];
                 } elseif (count($primaryKeys) == 1) {
                     $indexData['fid'] = $value[$primaryKeys[0]];
                 } elseif (count($primaryKeys)) {
                     $fids = array();
                     foreach ($primaryKeys as $pk) {
                         $fids[$pk] = $value[$pk];
                     }
                     $indexData['fid'] = json_encode($fids);
                 }
                 if (is_null($indexData['fid'])) {
                     $indexData['fid'] = $this->getMinFID();
                 }
                 if (array_key_exists('re_id', $value)) {
                     $indexData['catid'] = $value['re_id'];
                     if ($_table == $this->tablePrefix . 'article') {
                         $indexData['catid'] = intval($value['startpage']) ? $value['id'] : $value['re_id'];
                     }
                 } elseif (array_key_exists('category_id', $value)) {
                     $indexData['catid'] = $value['category_id'];
                 } else {
                     $indexData['catid'] = NULL;
                 }
                 $additionalValues = array();
                 foreach ($this->includeColumns[$_table] as $col) {
                     $additionalValues[$col] = $value[$col];
                 }
                 $indexData['values'] = $insert->escape(serialize($additionalValues));
                 $indexData['unchangedtext'] = $insert->escape((string) $value[$_column]);
                 $indexData['plaintext'] = $insert->escape($plaintext = $this->getPlaintext($value[$_column]));
                 foreach (preg_split($this->encodeRegex('~[[:punct:][:space:]]+~ism'), $plaintext) as $keyword) {
                     if ($this->significantCharacterCount <= mb_strlen($keyword, 'UTF-8')) {
                         $keywords[] = array('search' => $keyword, 'clang' => is_null($indexData['clang']) ? false : $indexData['clang']);
                     }
                 }
                 $indexData['teaser'] = '';
                 if ($this->tablePrefix . 'article' == $_table) {
                     $rex_article = new rex_article(intval($value['id']), intval($value['clang']));
                     $teaser = true;
                     $article_content_file = $this->generatedPath . '/articles/' . intval($value['id']) . '.' . intval($value['clang']) . '.content';
                     if (!file_exists($article_content_file)) {
                         include_once $this->includePath . "/functions/function_rex_generate.inc.php";
                         $generated = rex_generateArticleContent(intval($value['id']), intval($value['clang']));
                         if ($generated !== true) {
                             $teaser = false;
                             continue;
                         }
                     }
                     if (file_exists($article_content_file) and preg_match($this->encodeRegex('~(header\\s*\\(\\s*["\']\\s*Location\\s*:)|(rex_redirect\\s*\\()~is'), rex_get_file_contents($article_content_file))) {
                         $teaser = false;
                     }
                     $indexData['teaser'] = $teaser ? $insert->escape($this->getTeaserText($this->getPlaintext($rex_article->getArticle()))) : '';
                 }
                 $insert->setTable($this->tablePrefix . '587_searchindex');
                 $insert->setValues($indexData);
                 $insert->insert();
                 $count++;
             }
         }
         $this->storeKeywords($keywords, false);
         $this->endFrontendMode();
     } else {
         return false;
     }
     return $count;
 }