/** * @debug php cli.php main */ public function mainAction() { $industrys = Industry::find()->toArray(); foreach ($industrys as $key => $industry) { if ($industry['SubIndustryCode'] == 37) { $this->keywords = array(); $this->_list($industry['SubIndustryCode'] . '.html', $this->prefix); $insert = Industry::findFirst($industry['id']); $insert->Keywords = implode(',', $this->keywords); if ($insert->save() == false) { foreach ($insert->getMessages() as $error) { echo $error, "\n"; } } else { echo PHP_EOL; echo $industry['SubIndustryCode'] . '/' . $industry['SubIndustry'] . '/Done'; echo PHP_EOL; } } } }
/** * * @debug http://test.phalcon.loc/industry/extend */ public function entendAction() { $lensort = function ($a, $b) { $la = mb_strlen($a, 'UTF-8'); $lb = mb_strlen($b, 'UTF-8'); if ($la == $lb) { return 0; } return $la > $lb ? 1 : -1; }; $industrys = Industry::find()->toArray(); foreach ($industrys as $key => $industry) { $keywords = explode(',', $industry['Keywords']); $sortKeywords = array(); foreach ($keywords as $k => $keyword) { if (strpos($keyword, '、') !== false) { $cells = explode('、', $keyword); foreach ($cells as $kk => $cell) { if (array_search($cell, $sortKeywords) === false) { array_push($sortKeywords, $cell); } } } else { array_push($sortKeywords, $keyword); } } usort($sortKeywords, $lensort); $sortKeywords = implode(',', $sortKeywords); $update = Industry::findFirst($industry['id']); $update->ExtendSortKeywords = $sortKeywords; if ($update->save() == false) { foreach ($update->getMessages() as $error) { echo $error, "\n"; } } else { echo 'OK'; } } exit; }