NetCommons3 / Mails

Mails Plugin for NetCommons
1 stars 1 forks source link

afterSaveで`model->find`の`all`を指定しても1件しかとれない #50

Closed akagane99 closed 8 years ago

akagane99 commented 8 years ago
// 承認ONで、承認者が公開中の記事を編集しても、メール送らない
// 承認OFFで、公開中の記事を編集しても、メール送らない
// ・keyに対して2件以上記事がある = 編集
// ・公開中の記事(1つ前の記事のstatus=1)
// ・編集した記事が公開(status=1)
// ・承認ONで公開中の記事を編集して、編集した記事が公開なのは、承認者だけ
// ・・結果、承認ONでもOFFでも、公開中の記事を編集して、公開だったら、メール送らない

上記を実装するため、1つ前の記事が取得したかった。 しかし、afterSaveでmodel->findallを指定しても1件しかとれない。 なんでだ? 他の読み込んでいるビヘイビアの影響?

public function afterSave(Model $model, $created, $options = array()) {
    $data = $model->find('all', array(
        'recursive' => -1,
        'conditions' => array($model->alias . '.key' => $model->data[$model->alias]['key']),
        'order' => array($model->alias . '.modified DESC'),
    ));
    CakeLog::debug(print_r($data, true));

    // 色々な処理・・・
}

CakeLog::debug(print_r($data, true));

2016-03-22 09:19:47 Debug: Array
(
    [0] => Array
        (
            [Video] => Array
                (
                    [id] => 91
                    [key] => 57182801bbe75baa3aa5168722f22a80
                    [language_id] => 2
                    [block_id] => 5
                    [title] => 11122
                    [video_time] => 11
                    [play_number] => 1
                    [description] => 2
                    [status] => 2
                    [is_active] => 
                    [is_latest] => 
                    [created_user] => 4
                    [created] => 2016-03-21 10:05:09
                    [modified_user] => 4
                    [modified] => 2016-03-21 10:05:09
                )

            [ContentCommentCnt] => Array
                (
                    [content_key] => 57182801bbe75baa3aa5168722f22a80
                    [cnt] => 0
                )

            [UploadFile] => Array
                (
                    [video_file] => Array
                        (
                            [id] => 109
                            [plugin_key] => videos
                            [content_key] => 57182801bbe75baa3aa5168722f22a80
                            [field_name] => video_file
                            [original_name] => video1.mp4
                            [path] => files/upload_file/real_file_name/1/
                            [real_file_name] => ef4ac246226cf2f9896c0d978c71541f.mp4
                            [extension] => mp4
                            [mimetype] => video/mp4
                            [size] => 4544587
                            [download_count] => 16
                            [total_download_count] => 16
                            [room_id] => 1
                            [block_key] => c10b281de241a52ae151cb8ea569b01a
                            [created_user] => 4
                            [created] => 2016-03-21 10:05:09
                            [modified_user] => 4
                            [modified] => 2016-03-21 10:05:09
                        )

                    [thumbnail] => Array
                        (
                            [id] => 110
                            [plugin_key] => videos
                            [content_key] => 57182801bbe75baa3aa5168722f22a80
                            [field_name] => thumbnail
                            [original_name] => ef4ac246226cf2f9896c0d978c71541f.jpg
                            [path] => files/upload_file/real_file_name/1/
                            [real_file_name] => b78bac27871a3e7183e02eaf0546615c.jpg
                            [extension] => jpg
                            [mimetype] => image/jpeg
                            [size] => 62325
                            [download_count] => 26
                            [total_download_count] => 26
                            [room_id] => 1
                            [block_key] => c10b281de241a52ae151cb8ea569b01a
                            [created_user] => 4
                            [created] => 2016-03-21 10:05:09
                            [modified_user] => 4
                            [modified] => 2016-03-21 10:05:09
                        )

                )

        )

)
akagane99 commented 8 years ago

コントローラーで同じように書いてみたけどkey指定でaftersaveと同じ1件だった。 ビヘイビアで条件追加されてそう。

    $data = $model->find('all', array(
        'recursive' => -1,
        'conditions' => array($model->alias . '.key' => $model->data[$model->alias]['key']),
        'order' => array($model->alias . '.modified DESC'),
    ));
    CakeLog::debug(print_r($data, true));
akagane99 commented 8 years ago
//      'ContentComments.ContentComment',

ビヘイビアを外したらいけた。バグっぽい。