Esempio n. 1
0
 public function actionImportHoles()
 {
     set_time_limit(0);
     $holes = BHoles::model()->findAll();
     $count = 0;
     foreach ($holes as $hole) {
         //if (1){
         if ($hole->picturenames && isset($hole->picturenames['medium']['fresh']) && count($hole->picturenames['medium']['fresh']) > 0) {
             $model = new Holes('import');
             $model->attributes = $hole->attributes;
             $model->ID = $hole->ID;
             $type = HoleTypes::model()->find('alias = "' . $hole->TYPE . '"');
             $model->TYPE_ID = $type->id;
             if ($model->ADR_SUBJECTRF) {
                 $gibdd = GibddHeads::model()->find('is_regional=1 AND subject_id=' . $model->ADR_SUBJECTRF);
                 if ($gibdd) {
                     $model->gibdd_id = $gibdd->id;
                 } else {
                     $model->gibdd_id = 0;
                 }
             } else {
                 $model->gibdd_id = 0;
             }
             //if ($model->errors) print_r ($model->errors);
             if ($model->STATE == "inprogress") {
                 if (!$model->DATE_SENT) {
                     $model->DATE_SENT = $model->DATE_CREATED;
                 }
                 //echo date('d.m.Y', $model->DATE_SENT).'<br/>';
             }
             if ($model->save()) {
                 //if (0){
                 $count++;
                 foreach ($hole->picturenames['medium']['fresh'] as $i => $src) {
                     $picture = new HolePictures();
                     $picture->type = 'fresh';
                     $picture->filename = $src;
                     $picture->hole_id = $hole->ID;
                     $picture->user_id = $model->USER_ID;
                     $picture->ordering = $i;
                     $picture->save();
                 }
                 foreach ($hole->picturenames['medium']['fixed'] as $i => $src) {
                     $picture = new HolePictures();
                     $picture->type = 'fixed';
                     $picture->filename = $src;
                     $picture->hole_id = $hole->ID;
                     $picture->user_id = $model->USER_ID;
                     $picture->ordering = $i;
                     $picture->save();
                 }
                 if ($model->STATE == "fixed") {
                     $fixmodel = new HoleFixeds();
                     $fixmodel->user_id = $model->USER_ID;
                     $fixmodel->hole_id = $model->ID;
                     $fixmodel->date_fix = $model->DATE_STATUS;
                     $fixmodel->comment = $model->COMMENT2;
                     $fixmodel->save();
                 }
                 if ($model->STATE != "fresh") {
                     if (!$model->DATE_SENT) {
                         $model->DATE_SENT = $model->DATE_CREATED;
                     }
                     $request = new HoleRequests();
                     $request->hole_id = $model->ID;
                     $request->user_id = $model->USER_ID;
                     $request->gibdd_id = $model->gibdd_id;
                     $request->date_sent = $model->DATE_SENT;
                     $request->type = 'gibdd';
                     $request->save();
                     if ($model->GIBDD_REPLY_RECEIVED) {
                         $answer = new HoleAnswers('import');
                         //$answer->attributes=Array('uppload_files'=>Array(123,456));
                         $answer->isimport = true;
                         $answer->request_id = $request->id;
                         $answer->date = $model->DATE_STATUS;
                         $answer->comment = $model->COMMENT_GIBDD_REPLY;
                         if ($answer->save()) {
                             $dir = $_SERVER['DOCUMENT_ROOT'] . $answer->filesFolder;
                             if (!is_dir($_SERVER['DOCUMENT_ROOT'] . '/upload/st1234/answers/')) {
                                 mkdir($_SERVER['DOCUMENT_ROOT'] . '/upload/st1234/answers/');
                             }
                             if (!is_dir($_SERVER['DOCUMENT_ROOT'] . '/upload/st1234/answers/' . $answer->request->hole->ID)) {
                                 mkdir($_SERVER['DOCUMENT_ROOT'] . '/upload/st1234/answers/' . $answer->request->hole->ID);
                             }
                             if (!is_dir($dir)) {
                                 mkdir($dir);
                             }
                             if (!is_dir($dir . '/thumbs')) {
                                 mkdir($dir . '/thumbs');
                             }
                             foreach ($hole->picturenames['medium']['gibddreply'] as $i => $src) {
                                 $pict = new HoleAnswerFiles();
                                 $pict->file_name = $src;
                                 $pict->file_type = 'image';
                                 $pict->answer_id = $answer->id;
                                 copy($_SERVER['DOCUMENT_ROOT'] . '/upload/st1234/original/' . $answer->request->hole->ID . '/' . $src, $dir . '/' . $src);
                                 //unlink ($_SERVER['DOCUMENT_ROOT'].'/upload/st1234/original/'.$src);
                                 copy($_SERVER['DOCUMENT_ROOT'] . '/upload/st1234/medium/' . $answer->request->hole->ID . '/' . $src, $dir . '/thumbs/' . $src);
                                 //unlink ($_SERVER['DOCUMENT_ROOT'].'/upload/st1234/medium/'.$src);
                                 $pict->save();
                             }
                         } else {
                             print_r($answer->errors);
                             die;
                         }
                     }
                 }
             }
         }
     }
     echo "Добавлено {$count} ям.";
 }
Esempio n. 2
0
	<?php 
if (Holes::getDbConnection()->getSchema()->getTable(Holes::tableName()) === null) {
    ?>
	<?php 
    echo CHtml::ajaxLink('Cоздать структуру данных > ', $this->createUrl('makedata'), array('update' => '#makedata_result', 'beforeSend' => 'function(){
                                        $("#makedata_result").addClass("loading");
                                    }', 'complete' => 'function(){                                        
                                        $("#makedata_result").removeClass("loading");
                                    }'));
    ?>
    <div id="makedata_result"></div>                            
	<?php 
}
?>
	<?php 
if (BHoles::getDbConnection()->getSchema()->getTable(BHoles::tableName())) {
    ?>
	<?php 
    echo CHtml::ajaxLink('Импорт пользователей из старой базы > ', $this->createUrl('importUsers'), array('update' => '#importusers_result', 'beforeSend' => 'function(){
                                        $("#importusers_result").addClass("loading");
                                    }', 'complete' => 'function(){                                        
                                        $("#importusers_result").removeClass("loading");
                                    }'));
    ?>
    <div id="importusers_result"></div>   
    
    <?php 
    echo CHtml::ajaxLink('Импорт ям из старой базы > ', $this->createUrl('importHoles'), array('update' => '#importholes_result', 'beforeSend' => 'function(){
                                        $("#importholes_result").addClass("loading");
                                    }', 'complete' => 'function(){                                        
                                        $("#importholes_result").removeClass("loading");