61 private $removalExt = array(
'del');
65 private $newsExt = array(
'xml');
69 private $imagesExt = array(
'jpg');
73 private $videosExt = array(
'mp4');
77 private $log_filename;
81 private $relations = array();
85 private $isNew =
false;
89 public static $instance;
96 $this->log_filename .=
"log_{$time}.txt";
98 $channelAlias =
"apalines.content.$name";
100 $module = Yii::app()->getModule(
'apalines');
101 if(isset($module->channels[$name][
'delivery_path'])){
102 $channelAlias = $module->channels[$name][
'delivery_path'];
105 $this->path = Yii::getPathOfAlias($channelAlias);
106 $this->fertigPath = $this->path.DIRECTORY_SEPARATOR.
'fertig.txt';
108 if (file_exists($this->fertigPath)) {
109 unlink($this->fertigPath);
114 if (file_exists($this->path)) {
115 Yii::app()->log->routes[
'file']->setLogPath($this->path);
116 Yii::app()->log->routes[
'file']->setLogFile($this->log_filename);
124 $this->workPath = Yii::getPathOfAlias(
"$channelAlias.work");
125 $this->donePath = Yii::getPathOfAlias(
"$channelAlias.done");
126 $this->errorPath = Yii::getPathOfAlias(
"$channelAlias.error");
128 $wwwApaPath = Yii::getPathOfAlias(
"site.frontend.www.apalines");
129 $this->wwwPath = Yii::getPathOfAlias(
"site.frontend.www.apalines.$name");
130 $this->imagesPath = Yii::getPathOfAlias(
"site.frontend.www.apalines.$name.images");
131 $this->videosPath = Yii::getPathOfAlias(
"site.frontend.www.apalines.$name.videos");
133 if (file_exists($this->path)) {
134 if (!file_exists($this->workPath)) {
135 mkdir($this->workPath);
137 if (!file_exists($this->donePath)) {
138 mkdir($this->donePath);
140 if (!file_exists($this->errorPath)) {
141 mkdir($this->errorPath);
143 if (!file_exists($wwwApaPath)) {
146 if (!file_exists($this->wwwPath)) {
147 mkdir($this->wwwPath);
149 if (!file_exists($this->imagesPath)) {
150 mkdir($this->imagesPath);
152 if (!file_exists($this->videosPath)) {
153 mkdir($this->videosPath);
157 self::$instance = $this;
177 return substr(strrchr($filename,
'.'), 1);
184 if (is_dir($this->workPath)) {
185 if ($dh = opendir($this->workPath)) {
186 while (($file = readdir($dh)) !==
false) {
187 if (!is_file($this->
makeWorkPath($file)) || $file ==
'.DS_Store') {
191 if (in_array($this->
getExt($file),$this->removalExt)){
198 while (($file = readdir($dh)) !==
false) {
199 if (!is_file($this->
makeWorkPath($file)) || $file ==
'.DS_Store') {
203 else if (in_array($this->
getExt($file),$this->newsExt)) {
205 $this->
processNews($xml, $file, array(
'DOK_MELDUNG'));
210 while (($file = readdir($dh)) !==
false) {
211 if (!is_file($this->
makeWorkPath($file)) || $file ==
'.DS_Store') {
215 else if (in_array($this->
getExt($file),$this->newsExt)) {
217 $this->
processNews($xml, $file, array(
'DOK_BILD',
'DOK_VIDEO'));
220 else if (in_array($this->
getExt($file),$this->imagesExt)) {
225 else if (in_array($this->
getExt($file),$this->videosExt)) {
245 function processNews($xml, $xml_filename = null, $specific =
false)
249 $docType = $parserXML->getDocType();
251 if ($specific && is_array($specific) && !in_array($docType, $specific)) {
255 switch($parserXML->getDocType()) {
259 case 'DOK_BILD' ||
'DOK_VIDEO':
260 $isSuccess = $this->
processBild($parserXML, $xml_filename);
281 $line =
ApalinesNews::model()->find(
'docid = :docid',array(
':docid'=>$parserXML->getDocId()));
282 $isExist = isset($line);
286 $line->docid = $parserXML->getDocId();
287 $line->channel = $this->name;
289 $line->deleteFiles();
292 $line->apa_id = $parserXML->getApaId();
293 $line->title = $parserXML->getTitle();
294 $line->ndate = $parserXML->getDate();
295 $line->content = $parserXML->getText();
296 $line->place = $parserXML->getPlace();
297 $line->source = $parserXML->getSource();
298 $line->keywords = $parserXML->getKeywords();
299 $line->author = $parserXML->getAuthor();
300 $line->teaser = $parserXML->getTeaser();
301 $line->filename = $parserXML->getFilename();
302 $line->xml_filename = $xml_filename;
304 $relations = $parserXML->getRelations();
305 $this->relations = CMap::mergeArray(
307 array($line->xml_filename => $relations)
310 if (isset($line->id)) {
311 $childNews =
ApalinesNews::model()->findAll(
'related_maindoc_id=:id', array(
':id'=>$line->id));
312 foreach ($childNews as $child) {
313 if (!in_array($child->xml_filename, $relations)) {
317 if (empty($relations)) {
318 $line->background_news = 0;
322 if ($is_success = $line->save()) {
324 Yii::log(
"{$line->xml_filename} done update doc_id:{$line->docid} title:{$line->title} DOK_MELDUNG",
'info');
326 Yii::log(
"{$line->xml_filename} done insert doc_id:{$line->docid} title:{$line->title} DOK_MELDUNG",
'info');
330 Yii::log(
"{$line->xml_filename} error update doc_id:{$line->docid} title:{$line->title} DOK_MELDUNG",
'info');
332 Yii::log(
"{$line->xml_filename} error insert doc_id:{$line->docid} title:{$line->title} DOK_MELDUNG",
'info');
348 array(
':docid'=>$parserXML->getDocId()));
349 $isExist = isset($line);
353 $line->docid = $parserXML->getDocId();
354 $line->channel = $this->name;
357 $line->apa_id = $parserXML->getApaId();
358 $line->title = $parserXML->getTitle();
359 $line->ndate = $parserXML->getDate();
360 $line->place = $parserXML->getPlace();
361 $line->source = $parserXML->getSource();
362 $line->keywords = $parserXML->getKeywords();
363 $line->author = $parserXML->getAuthor();
364 $line->filename = $parserXML->getFilename();
365 $line->xml_filename = $xml_filename;
367 $line->type = ($parserXML->getDocType() ==
'DOK_BILD')? 0 : 1;
369 $files = $parserXML->getFiles();
371 if ($is_success = $line->save()) {
372 foreach($files as $file) {
374 $model->attributes = $file;
375 switch ($model->size) {
377 $model->size = ApalinesFile::ORIGINAL;
380 $model->size = ApalinesFile::THUMBNAIL;
383 $model->size = ApalinesFile::HIRES;
386 $model->parent_id = $line->id;
391 Yii::log(
"{$line->xml_filename} done update doc_id:{$line->docid} title:{$line->title} BILD",
'info');
393 Yii::log(
"{$line->xml_filename} done insert doc_id:{$line->docid} title:{$line->title} BILD",
'info');
397 Yii::log(
"{$line->xml_filename} error update doc_id:{$line->docid} title:{$line->title} BILD",
'info');
399 Yii::log(
"{$line->xml_filename} error insert doc_id:{$line->docid} title:{$line->title} BILD",
'info');
415 $deleteId = $parserXML->getDeleteId();
419 $line =
ApalinesMM::model()->find(
'docid = :docid',array(
':docid'=> $deleteId ));
425 Yii::log(
"{$line->xml_filename} done delete docid:{$line->docid} title:{$line->title}",
'info');
429 Yii::log(
"{$xml_filename} error delete",
'info');
439 $module = Yii::app()->getModule(
'apalines');
440 $max_age_of_news =
false;
441 if (isset($module->channels[$this->name][
'max_age_of_news'])) {
442 $max_age_of_news = $module->channels[$this->name][
'max_age_of_news'];
444 if (!$max_age_of_news && isset($module->total_max_age_of_news)) {
445 $max_age_of_news = $module->total_max_age_of_news;
447 if (!$max_age_of_news) {
452 'condition' =>
'channel = :channel AND deleted <> 1 AND (FROM_UNIXTIME(ndate) < (NOW() - interval :max_age_of_news hour))',
454 ':channel' => $this->name,
455 ':max_age_of_news' => $max_age_of_news
459 foreach ($news as $line) {
470 foreach ($files as $file) {
473 Yii::log(
"{$file} done delete image",
'info');
475 Yii::log(
"{$file} done delete video",
'info');
485 $multimedia =
ApalinesMM::model()->findAll(
'channel = :channel AND deleted=0 AND related_maindoc_id=0', array(
':channel'=> $this->name));
486 foreach ($multimedia as $mm) {
495 foreach($this->relations as $parent_xml_filename => $children){
497 $parent =
ApalinesNews::model()->find(
'xml_filename = :xml_filename',array(
':xml_filename'=>$parent_xml_filename));
498 if (isset($parent)) {
500 foreach ($children as $child_xml_filename) {
501 $child =
ApalinesNews::model()->find(
'xml_filename = :xml_filename', array(
':xml_filename'=>$child_xml_filename));
502 if (!isset($child)) {
503 $child =
ApalinesMM::model()->find(
'xml_filename = :xml_filename', array(
':xml_filename'=>$child_xml_filename));
508 $parent->background_news = 1;
510 $child->related_maindoc_id = $parent->id;
528 return $folder.DIRECTORY_SEPARATOR.$file;
539 return $this->
makePath($this->workPath, $file);
550 return $this->
makePath($this->donePath, $file);
561 return $this->
makePath($this->errorPath, $file);
572 return $this->
makePath($this->imagesPath, $file);
583 return $this->
makePath($this->videosPath, $file);
590 if (is_dir($this->path)) {
591 if ($dh = opendir($this->path)) {
592 while (($file = readdir($dh)) !==
false) {
593 $path = $this->
makePath($this->path,$file);
594 $path_parts = pathinfo($path);
595 if(!is_file($path)||$path_parts[
'extension']==
'txt'){
598 rename($this->
makePath($this->path,$file),