public function stAction() { $request = $this->getRequest(); $query = $request->getParam('q'); $db = $this->db; $db->setFetchMode(Zend_Db::FETCH_OBJ); $select = $db->select(); $select->from('KutuCatalog', '*'); if (isset($query) && !empty($query)) { $select->where($query); } $select->order('createdDate ASC'); $rowsFound = $db->fetchAll($select); echo 'There are ' . count($rowsFound) . " catalog(s)\n"; $rowCount = count($rowsFound); for ($iCount = 0; $iCount < $rowCount; $iCount++) { $row = $rowsFound[$iCount]; if (isset($rowsFound[$iCount + 1])) { $nextRow = $rowsFound[$iCount + 1]; $n = "-next:[" . $nextRow->guid . "]"; } else { $n = ''; } echo 'urutan: ' . $iCount . " - "; if ($row->profileGuid == 'klinik') { $title = $this->getCatalogAttribute($row->guid, 'fixedCommentTitle'); } else { $title = $this->getCatalogAttribute($row->guid, 'fixedTitle'); } if ($title) { $slug = Pandamp_Utility_String::removeSign($title, '-', true); $db->update('KutuCatalog', ['shortTitle' => $slug], "guid='{$row->guid}'"); try { //update document $this->addHitsBySolr(json_encode([["id" => $row->guid, "shortTitle" => ["set" => $slug], "modifiedDate" => ["set" => date("Y-m-d\\TH:i:s\\Z")]]])); } catch (Zend_Exception $e) { throw new Zend_Exception($e->getMessage()); } } echo "guid:[" . $row->guid . "][" . $row->createdDate . "]" . $n . "\n"; flush(); } sleep(1); echo "Fix st completed\n"; }
public function updatecatalogattributeAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(TRUE); $request = $this->getRequest(); $catalogGuid = $request->getParam('guid'); $title = $request->getParam('title'); $attributeGuid = $request->getParam('attributeGuid'); $catalogAttributeDb = new App_Model_Db_Table_CatalogAttribute(); $catalogAttributeDb->update(array('value' => $title), array('catalogGuid = ?' => $catalogGuid, 'attributeGuid = ?' => $attributeGuid)); //$indexingEngine = Pandamp_Search::manager(); //$indexingEngine->indexCatalog($catalogGuid); try { $this->view->addHitsBySolr(json_encode([["id" => $catalogGuid, "title" => ["set" => $title], "shortTitle" => ["set" => Pandamp_Utility_String::removeSign($title, '-', true)], "modifiedDate" => ["set" => date("Y-m-d\\TH:i:s\\Z")], "modifiedBy" => ["set" => Zend_Auth::getInstance()->getIdentity()->username]]])); } catch (Zend_Exception $e) { } $this->getResponse()->setBody('RESULT_OK'); }
public function save($aData) { if (empty($aData['profileGuid'])) { throw new Zend_Exception('Catalog Profile can not be EMPTY!'); } $profileGuid = $aData['profileGuid']; if ($profileGuid == 'klinik') { $title = $aData['fixedCommentTitle']; } else { $title = $aData['fixedTitle']; } $setsticky = false; $sticky = isset($aData['stickyCategory']) && !empty($aData['stickyCategory']) ? $aData['stickyCategory'] : 0; if ($sticky == 1) { $setsticky = true; } $slug = Pandamp_Utility_String::removeSign($title, '-', true); if (isset($aData['keywordintegrasi']) && !empty($aData['keywordintegrasi'])) { $ckey = explode(',', $aData['fixedKeywords']); $mckey = array_merge($aData['keywordintegrasi'], $ckey); $umckey = array_intersect_key($mckey, array_unique(array_map('strtolower', $mckey))); $umckey = rtrim(implode(',', $umckey), ','); $aData['fixedKeywords'] = $umckey; unset($aData['keywordintegrasi']); } if (isset($aData['fixedNarsum']) && !empty($aData['fixedNarsum'])) { $fn = implode(',', $aData['fixedNarsum']); $aData['fixedNarsum'] = $fn; } $tblCatalog = new App_Model_Db_Table_Catalog(); $gman = new Pandamp_Core_Guid(); $catalogGuid = isset($aData['guid']) && !empty($aData['guid']) ? $aData['guid'] : $gman->generateGuid(); $folderGuid = isset($aData['folderGuid']) && !empty($aData['folderGuid']) ? $aData['folderGuid'] : ''; if (isset($aData['shortTitle']) && !empty($aData['shortTitle'])) { $slug = $aData['shortTitle']; } //if not empty, there are 2 possibilities $where = $tblCatalog->getAdapter()->quoteInto('guid=?', $catalogGuid); if ($tblCatalog->fetchRow($where)) { $rowCatalog = $tblCatalog->find($catalogGuid)->current(); $rowCatalog->shortTitle = $slug; $rowCatalog->publishedDate = isset($aData['publishedDate']) ? $aData['publishedDate'] : $rowCatalog->publishedDate; $rowCatalog->expiredDate = isset($aData['expiredDate']) ? $aData['expiredDate'] : $rowCatalog->expiredDate; $rowCatalog->status = isset($aData['status']) ? $aData['status'] : $rowCatalog->status; $rowCatalog->price = isset($aData['price']) ? $aData['price'] : $rowCatalog->price; $rowCatalog->sticky = (int) $setsticky; } else { $rowCatalog = $tblCatalog->fetchNew(); $rowCatalog->guid = $catalogGuid; $rowCatalog->shortTitle = $slug; $rowCatalog->profileGuid = $profileGuid; $rowCatalog->publishedDate = isset($aData['publishedDate']) ? $aData['publishedDate'] : '0000-00-00 00:00:00'; $rowCatalog->expiredDate = isset($aData['expiredDate']) ? $aData['expiredDate'] : '0000-00-00 00:00:00'; $rowCatalog->createdBy = isset($aData['username']) ? $aData['username'] : ''; $rowCatalog->modifiedBy = $rowCatalog->createdBy; $rowCatalog->createdDate = date("Y-m-d H:i:s"); $rowCatalog->modifiedDate = $rowCatalog->createdDate; $rowCatalog->deletedDate = '0000-00-00 00:00:00'; $rowCatalog->status = isset($aData['status']) ? $aData['status'] : 0; $rowCatalog->price = isset($aData['price']) ? $aData['price'] : 0; $rowCatalog->sticky = (int) $setsticky; } try { $catalogGuid = $rowCatalog->save(); } catch (Exception $e) { die($e->getMessage()); } $tableProfileAttribute = new App_Model_Db_Table_ProfileAttribute(); //$profileGuid = $rowCatalog->profileGuid; $where = $tableProfileAttribute->getAdapter()->quoteInto('profileGuid=?', $profileGuid); $rowsetProfileAttribute = $tableProfileAttribute->fetchAll($where, 'viewOrder ASC'); $rowsetCatalogAttribute = $rowCatalog->findDependentRowsetCatalogAttribute(); foreach ($rowsetProfileAttribute as $rowProfileAttribute) { /*$aid = $rowProfileAttribute->attributeGuid; $rowCatalogAttribute = App_Model_Show_CatalogAttribute::show()->getCatalogAttributeValue( $catalogGuid, $rowProfileAttribute->attributeGuid); if ($rowCatalogAttribute) { $ca = new App_Model_Db_Table_CatalogAttribute(); $ca->update( [ 'value' => $aData[$aid] ], [ 'catalogGuid = ?' => $catalogGuid, 'attributeGuid = ?' => $rowProfileAttribute->attributeGuid ] ); } else { $ca = new App_Model_Db_Table_CatalogAttribute(); $ca->insert([ 'catalogGuid' => $catalogGuid, 'attributeGuid' => $rowProfileAttribute->attributeGuid, 'value' => $aData[$aid] ]); }*/ if ($rowsetCatalogAttribute->findByAttributeGuid($rowProfileAttribute->attributeGuid)) { $rowCatalogAttribute = $rowsetCatalogAttribute->findByAttributeGuid($rowProfileAttribute->attributeGuid); } else { $tblCatalogAttribute = new App_Model_Db_Table_CatalogAttribute(); $rowCatalogAttribute = $tblCatalogAttribute->fetchNew(); $rowCatalogAttribute->catalogGuid = $catalogGuid; $rowCatalogAttribute->attributeGuid = $rowProfileAttribute->attributeGuid; } $rowCatalogAttribute->value = isset($aData[$rowProfileAttribute->attributeGuid]) ? $aData[$rowProfileAttribute->attributeGuid] : ''; $rowCatalogAttribute->save(); } //category if (isset($aData['selectedNode']) && !empty($aData['selectedNode'])) { $categories = array_map('trim', explode(',', $aData['selectedNode'])); $tblCatalogFolder = new App_Model_Db_Table_CatalogFolder(); $cf = $tblCatalogFolder->fetchAll("catalogGuid='{$catalogGuid}'"); if (count($cf)) { foreach ($cf as $cfol) { $cts[] = $cfol->folderGuid; if (!in_array($cfol->folderGuid, $categories)) { $tblCatalogFolder->delete("catalogGuid='{$cfol->catalogGuid}' AND folderGuid='{$cfol->folderGuid}'"); } } } foreach ($categories as $category) { $rowCatalog->copyToFolder($category); } } //save to table CatalogFolder only if folderGuid is not empty /*if (!empty($folderGuid)) { $rowCatalog->copyToFolder($folderGuid); }*/ // copy to other categories /*if (!empty($aData['categories'])) { $tblCatalogFolder = new App_Model_Db_Table_CatalogFolder(); $cf = $tblCatalogFolder->fetchAll("catalogGuid='$catalogGuid'"); if (count($cf)) { $sa=""; foreach ($cf as $cfol) { $cts[] = $cfol->folderGuid; if (!in_array($cfol->folderGuid, $aData['categories'])) { $tblCatalogFolder->delete("catalogGuid='$cfol->catalogGuid' AND folderGuid='$cfol->folderGuid'"); $sa="del"; } } if ($sa=="del") { $auth = Zend_Auth::getInstance(); $group = $auth->getIdentity()->name; $group = strtolower(str_replace(" ", "", $group)); $zl = Zend_Registry::get("Zend_Locale"); $lang = $zl->getLanguage(); $cache = Pandamp_Cache::getInstance(); $sel = join("_", $cts); $cache->remove('categoryCheckbox_'.$sel.'_'.$lang.'_'.$group); } } foreach ($aData['categories'] as $category) { $rowCatalog->copyToFolder($category); } }*/ /** * @todo Relasi Katalog */ if (isset($aData['relIds'])) { $relatedItemDb = new App_Model_Db_Table_RelatedItem(); $relatedItemDb->delete(array('relatedGuid=?' => $catalogGuid, 'relateAs IN (?)' => array('RELATED_OTHER', 'RELATED_Clinic', 'RELATED_ISSUE', 'RELATED_HISTORY', 'RELATED_BASE', 'RELATED_TRANSLATION_ID', 'RELATED_TRANSLATION_EN'))); for ($i = 0; $i < count($aData['relIds']); $i++) { if ($aData['relIds'][$i] and $aData['relGuids'][$i]) { $relatedItemDb->insert(array('itemGuid' => $aData['relIds'][$i], 'relatedGuid' => $catalogGuid, 'relateAs' => $aData['relGuids'][$i])); } } } /** * @todo Upload File */ if (isset($aData['filename']) && !empty($aData['filename'])) { $catalogDb = new App_Model_Db_Table_Catalog(); for ($i = 0; $i < count($aData['filename']); $i++) { $fileName = $aData['filename'][$i]; $fileUrls = json_decode(stripslashes($aData['fileUrl'][$i])); foreach ($fileUrls as $index => $value) { if ($index == "original") { $title = ''; $slug = ''; if (isset($aData['attr_caption_' . $value->id]) && !empty($aData['attr_caption_' . $value->id])) { $title = $aData['attr_caption_' . $value->id][0]; $slug = Pandamp_Utility_String::removeSign($title, '-', true); } if ($value->type == 'file') { $relatedType = 'RELATED_FILE'; } elseif ($value->type == 'image') { $relatedType = 'RELATED_IMAGE'; } $rowDocCatalog = $catalogDb->fetchNew(); $rowDocCatalog->guid = $value->id; $rowDocCatalog->shortTitle = $slug; $rowDocCatalog->profileGuid = $aData['profile']; $docCatalogGuid = $rowDocCatalog->save(); $rowsetDocCatalogAttribute = $rowDocCatalog->findDependentRowsetCatalogAttribute(); $this->_updateCatalogAttribute($rowsetDocCatalogAttribute, $docCatalogGuid, 'docSystemName', $value->title); $this->_updateCatalogAttribute($rowsetDocCatalogAttribute, $docCatalogGuid, 'docOriginalName', $fileName); $this->_updateCatalogAttribute($rowsetDocCatalogAttribute, $docCatalogGuid, 'docSize', $value->size); $this->_updateCatalogAttribute($rowsetDocCatalogAttribute, $docCatalogGuid, 'docMimeType', $value->filetype); $this->_updateCatalogAttribute($rowsetDocCatalogAttribute, $docCatalogGuid, 'fixedTitle', $title); $this->_updateCatalogAttribute($rowsetDocCatalogAttribute, $docCatalogGuid, 'docViewOrder', 0); $this->relateTo($docCatalogGuid, $catalogGuid, $relatedType); } } } } /** * Copy|Use image * Untuk satu article satu image */ if (isset($aData['fixedFileImage'])) { $fixedFileImage = $aData['fixedFileImage']; $fixedFileImage = basename($fixedFileImage); if (strpos($fixedFileImage, 'tn_') !== false) { $basename = str_replace('tn_', '', $fixedFileImage); } else { $basename = str_replace('thumbnail_', '', $fixedFileImage); } $guidBasename = pathinfo($basename, PATHINFO_FILENAME); $eiTitle = $aData['fileImage'] ? $aData['fileImage'] : ''; $eslug = Pandamp_Utility_String::removeSign($eiTitle, '-', true); $rel = array(); $relatedItemDb = new App_Model_Db_Table_RelatedItem(); $relItems = $relatedItemDb->fetchAll("relatedGuid='" . $catalogGuid . "' AND relateAs='RELATED_IMAGE'"); if ($relItems) { foreach ($relItems as $relItem) { $catalogDb = new App_Model_Db_Table_Catalog(); $catalog = $catalogDb->fetchRow("guid='" . $relItem['itemGuid'] . "' AND status!=-1"); if ($catalog) { $rel[] = $relItem['itemGuid']; } } } if (isset($rel[0]) && count($rel) == 1 && $rel[0] == $guidBasename) { $rowEImageCatalog = $tblCatalog->find($guidBasename)->current(); $rowEImageCatalog->shortTitle = $eslug; } else { if (isset($rel[0])) { $this->delete($rel[0]); } // jika ingin mengganti gambar dari yang sudah ada $of = $tblCatalog->find($guidBasename)->current(); if ($of) { $cd = $of->createdDate; $cb = $of->createdBy; } else { $cb = $aData['username']; $cd = date("Y-m-d H:i:s"); } $rowEImageCatalog = $tblCatalog->fetchNew(); $rowEImageCatalog->shortTitle = $eslug; $rowEImageCatalog->profileGuid = $aData['profile']; $rowEImageCatalog->createdDate = $cd; $rowEImageCatalog->createdBy = $cb; } $catalogEGuid = $rowEImageCatalog->save(); $rowsetEImageCatalogAttribute = $rowEImageCatalog->findDependentRowsetCatalogAttribute(); /** * @TODO docSystemName * digunakan sebagai inti|pemisah dari image * jika dia hasil copy dari catalog lain atau file original nya sendiri * maka yg diambil adalah attribute ini */ $this->_updateCatalogAttribute($rowsetEImageCatalogAttribute, $catalogEGuid, 'docSystemName', $basename); $this->_updateCatalogAttribute($rowsetEImageCatalogAttribute, $catalogEGuid, 'docOriginalName', App_Model_Show_CatalogAttribute::show()->getCatalogAttributeValue($guidBasename, 'docOriginalName')); $this->_updateCatalogAttribute($rowsetEImageCatalogAttribute, $catalogEGuid, 'docSize', App_Model_Show_CatalogAttribute::show()->getCatalogAttributeValue($guidBasename, 'docSize')); $this->_updateCatalogAttribute($rowsetEImageCatalogAttribute, $catalogEGuid, 'docMimeType', App_Model_Show_CatalogAttribute::show()->getCatalogAttributeValue($guidBasename, 'docMimeType')); $this->_updateCatalogAttribute($rowsetEImageCatalogAttribute, $catalogEGuid, 'docViewOrder', App_Model_Show_CatalogAttribute::show()->getCatalogAttributeValue($guidBasename, 'docViewOrder')); $this->_updateCatalogAttribute($rowsetEImageCatalogAttribute, $catalogEGuid, 'fixedTitle', $eiTitle); $this->relateTo($catalogEGuid, $catalogGuid, 'RELATED_IMAGE'); } /** * @todo BLOCK solr core-catalog */ $indexingEngine = Pandamp_Search::manager(); $indexingEngine->indexCatalog($catalogGuid); /** * @todo BLOCK New solr corehol $registry = Zend_Registry::getInstance(); $application = Zend_Registry::get(Pandamp_Keys::REGISTRY_APP_OBJECT); $res = $application->getOption('resources')['indexing']['solr']['write']; $esolr = new Pandamp_Search_Adapter_Esolr($res['host'], $res['port'], $res['dir4']); $esolr->indexCatalog($catalogGuid); */ /** * @todo BLOCK solr shortenerUrl core3 $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer'); if (null === $viewRenderer->view) { $viewRenderer->initView(); } $view = $viewRenderer->view; // create shortener url $kopel = Zend_Auth::getInstance()->getIdentity()->kopel; $cfg = Pandamp_Config::getConfig(); $config = Pandamp_Application::getOption('resources'); $indexingConfig = $config['indexing']['solr']['write']; $hukumn = new Pandamp_Search_Adapter_Solrh($indexingConfig['host'], $indexingConfig['port'], $indexingConfig['dir3']); $catalogAttributeDb = new App_Model_Db_Table_CatalogAttribute(); $zl = Zend_Registry::get('Zend_Locale'); if ($zl->getLanguage() == 'id') { if ($profileGuid == 'klinik') $url_content = $cfg->web->url->base.'/klinik/detail/'.$catalogGuid.'/'.$slug; else if (in_array($profileGuid, array('kutu_peraturan','kutu_putusan','kutu_peraturan_kolonial','kutu_rancangan_peraturan'))) $url_content = $cfg->web->url->base.'/pusatdata/detail/'.$catalogGuid.'/'.$view->getLabelNode($folderGuid).'/'.$folderGuid.'/'.$slug; else $url_content = $cfg->web->url->base.'/berita/baca/'.$catalogGuid.'/'.$slug; } else if ($zl->getLanguage() == 'en') { $url_content = $cfg->web->en->url->base.'/pages/'.$catalogGuid.'/'.$slug(strip_tags(title)); } //$q = "url:\"".$url_content."\" kopel:".$kopel; $q = "url:\"".$url_content."\""; $db = Zend_Registry::get('db4'); $data = array('url' => $url_content, 'createdate' => date("Y-m-d h:i:s"), 'remoteip' => Pandamp_Lib_Formater::getHttpRealIp(), 'kopel' => $kopel); $hits = $hukumn->find($q,0,1); if (isset($hits->response->docs[0])) { $row = $hits->response->docs[0]; $hid = $row->id; $db->update('urls',$data,"id=$hid"); } else { $insert = $db->insert('urls', $data); $hid = $db->lastInsertId('urls', 'id'); } // indexing shortener url $hukumn->indexCatalog($hid); */ /* try { $url = 'http://developers.facebook.com/tools/lint/?url={'.$url_content.'}&format=json'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_NOBODY, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_exec($ch); $retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); } catch (Exception $e) { //die($e->getMessage()); } */ /** * Updated Dec 10, 2013 06:01 */ //$dir = $cfg->cdn->hol->static->url . DS . 'temp' . DS . 'cache'; //Pandamp_Core_FileCache::clear($dir . DS . 'url'); //Pandamp_Core_FileCache::clear($dir . DS . 'action'); /* if (Pandamp_Pio::manager()->ping()) { Pandamp_Pio::manager()->addEvent([ 'guid' => $catalogGuid, 'category' => $profileGuid ]); } */ self::addCache($folderGuid); //after indexing, update isIndex and indexedDate in table KutuCatalog return $catalogGuid; }