Exemple #1
0
 function doBulkUpdate($filter, $do, $ids = array())
 {
     @set_time_limit(600);
     // [TODO] Temp!
     $change_fields = array();
     $custom_fields = array();
     // Make sure we have actions
     if (empty($do)) {
         return;
     }
     // Make sure we have checked items if we want a checked list
     if (0 == strcasecmp($filter, "checks") && empty($ids)) {
         return;
     }
     if (is_array($do)) {
         foreach ($do as $k => $v) {
             switch ($k) {
                 //				case 'x':
                 //					break;
                 default:
                     // Custom fields
                     //					if(substr($k,0,3)=="cf_") {
                     //						$custom_fields[substr($k,3)] = $v;
                     //					}
                     break;
             }
         }
     }
     $pg = 0;
     if (empty($ids)) {
         do {
             list($objects, $null) = DAO_KbArticle::search($this->params, 100, $pg++, SearchFields_KbArticle::ID, true, false);
             $ids = array_merge($ids, array_keys($objects));
         } while (!empty($objects));
     }
     $batch_total = count($ids);
     for ($x = 0; $x <= $batch_total; $x += 100) {
         $batch_ids = array_slice($ids, $x, 100);
         if (!empty($change_fields)) {
             DAO_KbArticle::update($batch_ids, $change_fields);
         }
         // Category deltas
         if (isset($do['category_delta'])) {
             DAO_KbArticle::setCategories($batch_ids, $do['category_delta'], false);
         }
         // Custom Fields
         //self::_doBulkSetCustomFields(ChCustomFieldSource_Address::ID, $custom_fields, $batch_ids);
         unset($batch_ids);
     }
     unset($ids);
 }
Exemple #2
0
 private function _handleImportKbArticle($xml)
 {
     static $categoryList = NULL;
     static $categoryMap = NULL;
     $title = (string) $xml->title;
     $created = intval((string) $xml->created_date);
     $content_b64 = (string) $xml->content;
     // Bad file
     if (empty($content_b64) || empty($title)) {
         return false;
     }
     if (NULL == $categoryMap || NULL == $categoryList) {
         $categoryList = DAO_KbCategory::getWhere();
         $categoryMap = DAO_KbCategory::getTreeMap();
     }
     // Handle multiple <categories> elements
     $categoryIds = array();
     foreach ($xml->categories as $eCategories) {
         $pid = 0;
         $ptr =& $categoryMap[$pid];
         $categoryId = 0;
         foreach ($eCategories->category as $eCategory) {
             $catName = (string) $eCategory;
             //			echo "Looking for '", $catName, "' under $pid ...<br>";
             if (NULL == ($categoryId = $this->_getCategoryChildByName($categoryList, $ptr, $catName))) {
                 $fields = array(DAO_KbCategory::NAME => $catName, DAO_KbCategory::PARENT_ID => $pid);
                 $categoryId = DAO_KbCategory::create($fields);
                 //				echo " - Not found, inserted as $categoryId<br>";
                 $categoryList[$categoryId] = DAO_KbCategory::get($categoryId);
                 if (!isset($categoryMap[$pid])) {
                     $categoryMap[$pid] = array();
                 }
                 $categoryMap[$pid][$categoryId] = 0;
                 $categoryMap[$categoryId] = array();
                 $categoryIds[] = $categoryId;
             } else {
                 $categoryIds[] = $categoryId;
                 //				echo " - Found at $categoryId !<br>";
             }
             $pid = $categoryId;
             $ptr =& $categoryMap[$categoryId];
         }
     }
     // Decode content
     $content = base64_decode($content_b64);
     // [TODO] Dupe check?  (title in category)
     $fields = array(DAO_KbArticle::TITLE => $title, DAO_KbArticle::UPDATED => $created, DAO_KbArticle::FORMAT => 1, DAO_KbArticle::CONTENT_RAW => $content, DAO_KbArticle::CONTENT => $content, DAO_KbArticle::VIEWS => 0);
     if (null !== ($articleId = DAO_KbArticle::create($fields))) {
         DAO_KbArticle::setCategories($articleId, $categoryIds, false);
         return true;
     }
     return false;
 }
Exemple #3
0
 function saveArticleEditPanelAction()
 {
     $active_worker = CerberusApplication::getActiveWorker();
     if (!$active_worker->hasPriv('core.kb.articles.modify')) {
         return;
     }
     $translate = DevblocksPlatform::getTranslationService();
     @($id = DevblocksPlatform::importGPC($_REQUEST['id'], 'integer', 0));
     @($do_delete = DevblocksPlatform::importGPC($_REQUEST['do_delete'], 'integer', 0));
     @($title = DevblocksPlatform::importGPC($_REQUEST['title'], 'string'));
     @($category_ids = DevblocksPlatform::importGPC($_REQUEST['category_ids'], 'array', array()));
     @($content_raw = DevblocksPlatform::importGPC($_REQUEST['content_raw'], 'string'));
     @($format = DevblocksPlatform::importGPC($_REQUEST['format'], 'integer', 0));
     if (!empty($id) && !empty($do_delete)) {
         // Delete
         DAO_KbArticle::delete($id);
     } else {
         // Create|Modify
         // Sanitize
         if ($format > 2 || $format < 0) {
             $format = 0;
         }
         if (empty($title)) {
             $title = '(' . $translate->_('kb_article.title') . ')';
         }
         switch ($format) {
             default:
             case 0:
                 // plaintext
                 $content_html = $content_raw;
                 break;
             case 1:
                 // HTML
                 $content_html = $content_raw;
                 break;
         }
         if (empty($id)) {
             // create
             $fields = array(DAO_KbArticle::TITLE => $title, DAO_KbArticle::FORMAT => $format, DAO_KbArticle::CONTENT_RAW => $content_raw, DAO_KbArticle::CONTENT => $content_html, DAO_KbArticle::UPDATED => time());
             $id = DAO_KbArticle::create($fields);
         } else {
             // update
             $fields = array(DAO_KbArticle::TITLE => $title, DAO_KbArticle::FORMAT => $format, DAO_KbArticle::CONTENT_RAW => $content_raw, DAO_KbArticle::CONTENT => $content_html, DAO_KbArticle::UPDATED => time());
             DAO_KbArticle::update($id, $fields);
         }
         DAO_KbArticle::setCategories($id, $category_ids, true);
     }
 }