Пример #1
0
 /**
  * Controller-Processing
  */
 public function process()
 {
     parent::process();
     $db = $this->initDatabase();
     if (!$db) {
         die('0');
     }
     $data = $db->fetch($db->select('authors', '*'), true);
     $tmp = new \fpcm\model\files\tempfile(\fpcm\modules\nkorg\classicimporter\nkorgclassicimporter::mappingUser);
     $ids = array();
     $rmfile = new \fpcm\model\files\tempfile(\fpcm\modules\nkorg\classicimporter\nkorgclassicimporter::mappingRolls);
     $rollmapping = $rmfile->getContent();
     $rollmapping = json_decode($rollmapping, true);
     if ($rmfile->getFilesize() > 0 && !is_array($rollmapping)) {
         trigger_error('Unable to parse user roll mapping file');
         die('0');
     }
     foreach ($data as $user) {
         $author = new \fpcm\model\users\author();
         $author->disablePasswordSecCheck();
         $author->setUserName(utf8_encode($user->sysusr));
         $author->setDisplayName(utf8_encode($user->name));
         $author->setEmail(utf8_encode($user->email));
         $author->setRegistertime($user->registertime);
         $roll = isset($rollmapping[$user->usrlevel]) ? $rollmapping[$user->usrlevel] : 3;
         $author->setRoll($roll);
         $author->setPassword(utf8_encode($user->sysusr));
         $author->setUserMeta(array());
         $res = $author->save();
         if ($res !== true) {
             if ($res == \fpcm\model\users\author::AUTHOR_ERROR_EXISTS) {
                 trigger_error('User import failed, user already exists: ' . $author->getUsername());
             } else {
                 trigger_error('Unable to import user: '******'Classic Importer: No user ids found, maybe no users imported...');
         die('0');
     }
     $tmp->setContent(json_encode($ids));
     $tmp->save();
     die('1');
 }
Пример #2
0
 /**
  * Controller-Processing
  */
 public function process()
 {
     parent::process();
     $db = $this->initDatabase();
     if (!$db) {
         die('0');
     }
     $data = $db->fetch($db->select('categories', '*'), true);
     $tmp = new \fpcm\model\files\tempfile(\fpcm\modules\nkorg\classicimporter\nkorgclassicimporter::mappingCategories);
     $rmfile = new \fpcm\model\files\tempfile(\fpcm\modules\nkorg\classicimporter\nkorgclassicimporter::mappingRolls);
     $rollmapping = $rmfile->getContent();
     $rollmapping = json_decode($rollmapping, true);
     if ($rmfile->getFilesize() > 0 && !is_array($rollmapping)) {
         trigger_error('Unable to parse user roll mapping file');
         die('0');
     }
     $ids = array();
     foreach ($data as $cat) {
         $category = new \fpcm\model\categories\category();
         $category->setName(utf8_encode($cat->catname));
         $category->setIconPath(utf8_encode($cat->icon_path));
         $group = isset($rollmapping[$cat->minlevel]) ? $rollmapping[$cat->minlevel] : 1;
         $category->setGroups($group);
         $res = $category->save();
         if (!$res) {
             trigger_error('Unable to import category "' . utf8_encode($cat->catname) . '", maybe it already exists. Continue...');
             continue;
         }
         $ids[$cat->id] = \fpcm\classes\baseconfig::$fpcmDatabase->getLastInsertId();
     }
     if (!count($ids)) {
         \fpcm\classes\logs::syslogWrite('Classic Importer: No category ids found, maybe no categories imported...');
         die('0');
     }
     $tmp->setContent(json_encode($ids));
     $tmp->save();
     die('1');
 }
Пример #3
0
 /**
  * Controller-Processing
  */
 public function process()
 {
     parent::process();
     $id = (int) $this->getRequestVar('id');
     $db = $this->initDatabase();
     if (!$db) {
         die('0');
     }
     $tmp1 = new \fpcm\model\files\tempfile(\fpcm\modules\nkorg\classicimporter\nkorgclassicimporter::mappingUser);
     $usermapping = $tmp1->getContent();
     $usermapping = json_decode($tmp1->getContent(), true);
     $tmp2 = new \fpcm\model\files\tempfile(\fpcm\modules\nkorg\classicimporter\nkorgclassicimporter::mappingCategories);
     $categorymapping = $tmp2->getContent();
     $categorymapping = json_decode($tmp2->getContent(), true);
     if ($tmp2->getFilesize() > 0 && !is_array($categorymapping) || $tmp1->getFilesize() > 0 && !is_array($usermapping)) {
         trigger_error('Unable to parse user or category mapping files');
         die('0');
     }
     $newspost = $db->fetch($db->select('newsposts', '*', "id = {$id}"));
     $article = new \fpcm\model\articles\article();
     $content = html_entity_decode(htmlspecialchars_decode(utf8_encode($newspost->content)));
     $search = array('/data/upload/', '/thumb_');
     $replace = array('/data/uploads/', '/thumbs/');
     $titel = html_entity_decode(htmlspecialchars_decode(utf8_encode($newspost->titel)));
     $article->setContent(str_replace($search, $replace, $content));
     $article->setTitle($titel);
     $article->setCreatetime($newspost->writtentime);
     $article->setChangetime($newspost->editedtime ? $newspost->editedtime : $newspost->writtentime);
     $article->setComments($newspost->comments_active);
     $article->setDeleted($newspost->is_deleted);
     $article->setDraft($newspost->ispreview);
     $article->setArchived($newspost->is_archived);
     $article->setPinned($newspost->is_pinned);
     if ($newspost->writtentime > time()) {
         $article->setPostponed(true);
     }
     $article->setCategories(array(1));
     $newcategories = array();
     $oldcategories = explode(';', $newspost->category);
     if (is_array($categorymapping)) {
         if (count($oldcategories)) {
             foreach ($oldcategories as $categorie) {
                 if (!isset($categorymapping[$categorie])) {
                     continue;
                 }
                 $newcategories[] = (int) $categorymapping[$categorie];
             }
         }
     } else {
         $categoryList = new \fpcm\model\categories\categoryList();
         $categories = $categoryList->getCategoriesAll();
         foreach ($oldcategories as $categorie) {
             if (!isset($categories[$categorie])) {
                 continue;
             }
             $newcategories[] = $categories[$categorie]->getId();
         }
     }
     if (count($newcategories)) {
         $article->setCategories($newcategories);
     }
     if (is_array($usermapping) && isset($usermapping[$newspost->author])) {
         $article->setCreateuser($usermapping[$newspost->author]);
         $article->setChangeuser($usermapping[$newspost->author]);
     } else {
         $article->setCreateuser($newspost->author);
         $article->setChangeuser($newspost->author);
     }
     $article->prepareDataSave(true);
     $newid = $article->save();
     if (!$newid) {
         trigger_error('Unable to import article with ID ' . $id . '! Skipping comments...');
         usleep(500000);
         die('0');
     }
     $id = $newid != $id ? $newid : $id;
     $comments = $db->fetch($db->select('comments', '*', "newsid = {$id}"), true);
     if (!count($comments)) {
         usleep(750000);
         die('1');
     }
     foreach ($comments as $comment) {
         $newcomment = new \fpcm\model\comments\comment();
         $newcomment->setName(utf8_encode(htmlspecialchars_decode($comment->author_name)));
         $newcomment->setEmail(utf8_encode(htmlspecialchars_decode($comment->author_email)));
         $newcomment->setWebsite(utf8_encode(htmlspecialchars_decode($comment->author_url)));
         $newcomment->setText(htmlspecialchars_decode(utf8_encode($comment->comment_text)));
         $newcomment->setCreatetime($comment->comment_time);
         $newcomment->setIpaddress($comment->ip);
         $newcomment->setChangeuser($this->session->getUserId());
         $newcomment->setChangetime(time());
         if ($comment->status == 2) {
             $newcomment->setApproved(0);
         } elseif ($comment->status == 1) {
             $newcomment->setPrivate(1);
         } else {
             $newcomment->setApproved(1);
         }
         $newcomment->setArticleid($id);
         $newcomment->save();
     }
     usleep(750000);
     die('1');
 }