frontend/modules/elfind/src/elFinderVolumeLocalFileSystem.class.php
/**
     * fileversionsDialog for file or directory
     *
     * @param string $path
     * @return array
     */
fileversionsDialog for file or directory
@param string $path
@return array
fileversionsDialog for file or directory @param string $path @return array
protected function fileversionsDialogCE($path)
    {
        if (is_dir($path)) {
            $InfoFile = $path . '/' . UserFiles::DIR_INFO_FILE;
        } else {
            $InfoFile = $path;
        }
        if (!file_exists($InfoFile)) {
            return ['status' => false, 'info' => 'File info disabled.'];
        }
        try {
            $tmp = @unserialize(file_get_contents($InfoFile));
            if (!isset($tmp['file_uuid'], $tmp['file_id'])) {
                return ['status' => false, 'info' => self::ERROR_SYNCHRONIZATION];
            }
        } catch (Exception $e) {
            return ['status' => false, 'info' => self::ERROR_SYNCHRONIZATION];
        }
        $ret['hash'] = $this->encode($path);
        $User = Yii::$app->user->identity;
        $ret['payed'] = (!in_array($User->license_type, [Licenses::TYPE_FREE_DEFAULT])) ? true : false;
        $ret = $ret + UserFiles::getFileShareInfo($path);
        $UserFile = UserFiles::findOne(['file_id' => $ret['file_id']]);
        $query = "SELECT
                    t1.event_id,
                    t1.event_type,
                    t1.event_timestamp,
                    t1.diff_file_size,
                    t1.rev_diff_file_size,
                    t1.file_size_before_event,
                    t1.file_size_after_event,
                    t1.file_hash_before_event,
                    t1.file_hash as file_hash_after_event,
                    t1.is_rollback,
                    t1.event_invisible,
                    COALESCE(t2.user_email, 'unknown') as user_email
                  FROM {{%user_file_events}} as t1
                  LEFT JOIN {{%users}} as t2 ON t1.event_creator_user_id = t2.user_id
                  WHERE (t1.file_id = :file_id)
                  AND (t1.event_type IN (:TYPE_UPDATE, :TYPE_CREATE))
                  AND (t1.event_invisible = :EVENT_VISIBLE)
                  AND (t1.event_timestamp >= :event_timestamp)
                  ORDER BY t1.event_id DESC";
        $ret['fileversions'] = Yii::$app->db->createCommand($query, [
            'file_id'         => $ret['file_id'],
            'TYPE_UPDATE'     => UserFileEvents::TYPE_UPDATE,
            'TYPE_CREATE'     => UserFileEvents::TYPE_CREATE,
            'EVENT_VISIBLE'   => UserFileEvents::EVENT_VISIBLE,
            'event_timestamp' => time() - Preferences::getValueByKey('RestorePatchTTL', 2592000, 'int')
        ])->queryAll();
        $lock_all_next_restore = false;
        $i = 0;
        foreach ($ret['fileversions'] as $k=>$v) {
            $ret['fileversions'][$k]['status'] = 1;
            if ($lock_all_next_restore || (intval($ret['fileversions'][$k]['rev_diff_file_size']) == 0 && intval($ret['fileversions'][$k]['file_size_before_event']) != 0)) {
                $ret['fileversions'][$k]['status'] = 0;
                $lock_all_next_restore = true;
            }
            if ($i == 0) {
                $ret['fileversions'][$k]['status'] = -1;
                $ret['fileversions'][$k]['event_id'] = -1;
                $ret['fileversions'][$k]['diff_file_size'] = -1;
                $ret['fileversions'][$k]['rev_diff_file_size'] = -1;
            }
            if ($UserFile->file_md5 == $ret['fileversions'][$k]['file_hash_after_event']) {
                $i > 0
                    ? $ret['fileversions'][$k]['status'] = -2
                    : $ret['fileversions'][$k]['status'] = -1;
                $ret['fileversions'][$k]['event_id'] = -1;
                $ret['fileversions'][$k]['diff_file_size'] = -1;
                $ret['fileversions'][$k]['rev_diff_file_size'] = -1;
            }
            $ret['fileversions'][$k]['timestamp'] = $ret['fileversions'][$k]['event_timestamp'];
            $ret['fileversions'][$k]['event_timestamp'] = date(Yii::$app->params['datetime_short_format'], $ret['fileversions'][$k]['event_timestamp']);
            $ret['fileversions'][$k]['event_type'] = UserFileEvents::displayType($ret['fileversions'][$k]['event_type']);
            if ($ret['fileversions'][$k]['is_rollback'] == UserFileEvents::IS_ROLLBACK) {
                $ret['fileversions'][$k]['event_type'] = UserFileEvents::displayType(UserFileEvents::TYPE_ROLLBACK);
            }
            $i++;
        }
        $fileversions = [];
        foreach ($ret['fileversions'] as $k=>$v) {
            $fileversions[] = $v;
        }
        $ret['fileversions'] = $fileversions;
        if (!sizeof($ret['fileversions'])) {
            if ($UserFile && !$UserFile->is_folder) {
                $UserFile->is_updated = UserFiles::FILE_UNUPDATED;
                $UserFile->save();
                $relativePath = UserFiles::getFullPath($UserFile);
                $User = Users::getPathNodeFS($UserFile->user_id);
                $file_name = $User->_full_path . '/' . $relativePath;
                if (!file_exists($file_name)) {
                    FileSys::touch($file_name, UserFiles::CHMOD_DIR, UserFiles::CHMOD_FILE);
                }
                UserFiles::createFileInfo($file_name, $UserFile);
            }
        }
        return ['status' => true, 'data' => $ret];
    }
protected function fileversionsDialogCE ( $ path ) { if ( is_dir ( $ path ) ) { $ InfoFile = $ path . '/' . UserFiles :: DIR_INFO_FILE ; } else { $ InfoFile = $ path ; } if ( ! file_exists ( $ InfoFile ) ) { return [ 'status' => false , 'info' => 'File info disabled.' ] ; } try { $ tmp = @ unserialize ( file_get_contents ( $ InfoFile ) ) ; if ( ! isset ( $ tmp [ 'file_uuid' ] , $ tmp [ 'file_id' ] ) ) { return [ 'status' => false , 'info' => self :: ERROR_SYNCHRONIZATION ] ; } } catch ( Exception $ e ) { return [ 'status' => false , 'info' => self :: ERROR_SYNCHRONIZATION ] ; } $ ret [ 'hash' ] = $ this -> encode ( $ path ) ; $ User = Yii :: $ app -> user -> identity ; $ ret [ 'payed' ] = ( ! in_array ( $ User -> license_type , [ Licenses :: TYPE_FREE_DEFAULT ] ) ) ? true : false ; $ ret = $ ret + UserFiles :: getFileShareInfo ( $ path ) ; $ UserFile = UserFiles :: findOne ( [ 'file_id' => $ ret [ 'file_id' ] ] ) ; $ query = " SELECT
                    t1.event_id,
                    t1.event_type,
                    t1.event_timestamp,
                    t1.diff_file_size,
                    t1.rev_diff_file_size,
                    t1.file_size_before_event,
                    t1.file_size_after_event,
                    t1.file_hash_before_event,
                    t1.file_hash as file_hash_after_event,
                    t1.is_rollback,
                    t1.event_invisible,
                    COALESCE(t2.user_email, 'unknown') as user_email
                  FROM {{%user_file_events}} as t1
                  LEFT JOIN {{%users}} as t2 ON t1.event_creator_user_id = t2.user_id
                  WHERE (t1.file_id = :file_id)
                  AND (t1.event_type IN (:TYPE_UPDATE, :TYPE_CREATE))
                  AND (t1.event_invisible = :EVENT_VISIBLE)
                  AND (t1.event_timestamp >= :event_timestamp)
                  ORDER BY t1.event_id DESC " ; $ ret [ 'fileversions' ] = Yii :: $ app -> db -> createCommand ( $ query , [ 'file_id' => $ ret [ 'file_id' ] , 'TYPE_UPDATE' => UserFileEvents :: TYPE_UPDATE , 'TYPE_CREATE' => UserFileEvents :: TYPE_CREATE , 'EVENT_VISIBLE' => UserFileEvents :: EVENT_VISIBLE , 'event_timestamp' => time ( ) - Preferences :: getValueByKey ( 'RestorePatchTTL' , 2592000 , 'int' ) ] ) -> queryAll ( ) ; $ lock_all_next_restore = false ; $ i = 0 ; foreach ( $ ret [ 'fileversions' ] as $ k => $ v ) { $ ret [ 'fileversions' ] [ $ k ] [ 'status' ] = 1 ; if ( $ lock_all_next_restore || ( intval ( $ ret [ 'fileversions' ] [ $ k ] [ 'rev_diff_file_size' ] ) == 0 && intval ( $ ret [ 'fileversions' ] [ $ k ] [ 'file_size_before_event' ] ) != 0 ) ) { $ ret [ 'fileversions' ] [ $ k ] [ 'status' ] = 0 ; $ lock_all_next_restore = true ; } if ( $ i == 0 ) { $ ret [ 'fileversions' ] [ $ k ] [ 'status' ] = - 1 ; $ ret [ 'fileversions' ] [ $ k ] [ 'event_id' ] = - 1 ; $ ret [ 'fileversions' ] [ $ k ] [ 'diff_file_size' ] = - 1 ; $ ret [ 'fileversions' ] [ $ k ] [ 'rev_diff_file_size' ] = - 1 ; } if ( $ UserFile -> file_md5 == $ ret [ 'fileversions' ] [ $ k ] [ 'file_hash_after_event' ] ) { $ i > 0 ? $ ret [ 'fileversions' ] [ $ k ] [ 'status' ] = - 2 : $ ret [ 'fileversions' ] [ $ k ] [ 'status' ] = - 1 ; $ ret [ 'fileversions' ] [ $ k ] [ 'event_id' ] = - 1 ; $ ret [ 'fileversions' ] [ $ k ] [ 'diff_file_size' ] = - 1 ; $ ret [ 'fileversions' ] [ $ k ] [ 'rev_diff_file_size' ] = - 1 ; } $ ret [ 'fileversions' ] [ $ k ] [ 'timestamp' ] = $ ret [ 'fileversions' ] [ $ k ] [ 'event_timestamp' ] ; $ ret [ 'fileversions' ] [ $ k ] [ 'event_timestamp' ] = date ( Yii :: $ app -> params [ 'datetime_short_format' ] , $ ret [ 'fileversions' ] [ $ k ] [ 'event_timestamp' ] ) ; $ ret [ 'fileversions' ] [ $ k ] [ 'event_type' ] = UserFileEvents :: displayType ( $ ret [ 'fileversions' ] [ $ k ] [ 'event_type' ] ) ; if ( $ ret [ 'fileversions' ] [ $ k ] [ 'is_rollback' ] == UserFileEvents :: IS_ROLLBACK ) { $ ret [ 'fileversions' ] [ $ k ] [ 'event_type' ] = UserFileEvents :: displayType ( UserFileEvents :: TYPE_ROLLBACK ) ; } $ i ++ ; } $ fileversions = [ ] ; foreach ( $ ret [ 'fileversions' ] as $ k => $ v ) { $ fileversions [ ] = $ v ; } $ ret [ 'fileversions' ] = $ fileversions ; if ( ! sizeof ( $ ret [ 'fileversions' ] ) ) { if ( $ UserFile && ! $ UserFile -> is_folder ) { $ UserFile -> is_updated = UserFiles :: FILE_UNUPDATED ; $ UserFile -> save ( ) ; $ relativePath = UserFiles :: getFullPath ( $ UserFile ) ; $ User = Users :: getPathNodeFS ( $ UserFile -> user_id ) ; $ file_name = $ User -> _full_path . '/' . $ relativePath ; if ( ! file_exists ( $ file_name ) ) { FileSys :: touch ( $ file_name , UserFiles :: CHMOD_DIR , UserFiles :: CHMOD_FILE ) ; } UserFiles :: createFileInfo ( $ file_name , $ UserFile ) ; } } return [ 'status' => true , 'data' => $ ret ] ; }
fileversionsDialog for file or directory
 @param string $path
 @return array
fileversionsDialog for file or directory @param string $path @return array
//sleep(5); //return $this->setError("File info disabled."); //return $this->setError("Sync file error. Source folder_uuid does not exist."); /** @var \common\models\Users $User */ /*
            if ($ret['fileversions'][$k]['event_invisible'] == UserFileEvents::EVENT_INVISIBLE) {
                $ret['fileversions'][$k+1]['file_size_after_event'] = $ret['fileversions'][$k]['file_size_after_event'];
                unset($ret['fileversions'][$k]);
                continue;
            }
            */ //if (intval($ret['fileversions'][$k]['rev_diff_file_size']) == 0 || $lock_all_next_restore) { //var_dump($UserFile->file_md5); //var_dump($ret['fileversions'][$k]['file_hash_after_event']); //exit; //sort($ret['fileversions']); //var_dump($ret['fileversions']); exit; /* Проверим есть ли евенты апдейта, и если нет, то запишем в файл инфу что нет откатов у него */ //$UserFile = UserFiles::findOne(['file_id' => $ret['file_id']]); //var_dump($ret); exit;