S
S
Skrolea2016-07-10 18:53:22
MySQL
Skrolea, 2016-07-10 18:53:22

Duplicate photos. How to find the problem?

Good afternoon. I can’t get it (maybe if I ask the question correctly, then the answer will come up by itself).
There is a site on yii2. The site consists of 10 sections with photos in each section. Photos in each section are saved using

public function upload() {

        if ($this->validate()) {
            foreach ($this->imageFiles as $file) {

                $md5file = substr(md5(microtime() . uniqid()), 0, 10);

                if ($file->saveAs('uploads/' . $md5file . '.' . $file->extension)) {
                    $dbsave = new Photos();
                    $dbsave->action = $this->action;                    
                    $dbsave->url = 'uploads/' . $md5file . '.' . $file->extension;                    
                    $dbsave->thumb = 'uploads/thumbs/' . $md5file . '.' . $file->extension;            
                    Image::crop(Yii::getAlias($dbsave->url),580,710,[170,10]) ->save(Yii::getAlias($dbsave->thumb), ['quality' => 100]);                   
                    $dbsave->save();
                }
            }
            return true;
        } else {
            return false;
        }
    }

, where $this->action;is the section number. And everything was fine, until today I noticed that the newly uploaded photos to the section contain photos from earlier sections. Only 4 pieces. Useful to look - these four photos are in all the early sections. Those. I upload photos without them - these photos are not in the admin panel, but these photos are on the front. In the database, those "repeating" photos in their sections - I use the table
| id | url | thumb | action. I bring it to the front using
$searchModel = new PhotosSearch();
        $dataProvider = $searchModel->search($params);

        return $this->render('photos', [
                    'searchModel' => $searchModel,
                    'dataProvider' => $dataProvider,
                    'place' => $place, 'actionDate' => $actionDate
        ]);
, where I get params using 'url' => '/photos/5(номер раздела)'and pass to the model
public function search($params)
    {
            $query = Photos::find()->where(['action' => $params]);      

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => [
                'pageSize' => 6,
            ],
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // $query->where('0=1');
            return $dataProvider;
        }

  
        $query->andFilterWhere([
            'id' => $this->id,
            'action' => $this->action,
        ]);

        $query->andFilterWhere(['like', 'url', $this->url])
            ->andFilterWhere(['like', 'thumb', $this->thumb])
            ->andFilterWhere(['like', 'name', $this->name])
            ->andFilterWhere(['like', 'account', $this->account]);

        return $dataProvider;
    }

Any thoughts are needed. In general, any, up to "quit you this business"

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question