src/apis/ProxyController.php
public function actionIndex($identifier, $token)
    {
        $machine = ProxyMachine::findOne(['identifier' => $identifier, 'is_deleted' => false]);
        
        if (!$machine) {
            throw new ForbiddenHttpException("Unable to acccess the proxy api.");
        }
        
        if (sha1($machine->access_token) !== $token) {
            throw new ForbiddenHttpException("Unable to acccess the proxy api due to invalid token.");
        }
        
        $rowsPerRequest = $this->module->proxyRowsPerRequest;
        
        $config = [
            'rowsPerRequest' => $rowsPerRequest,
            'tables' => [],
            'storageFilesCount' => StorageFile::find()->count(),
        ];
        
        foreach (Yii::$app->db->schema->tableNames as $table) {
            if (in_array($table, $this->ignoreTables)) {
                continue;
            }
            
            $schema = Yii::$app->db->getTableSchema($table);
            $rows = (new Query())->from($table)->count();
            $config['tables'][$table] = [
                'pks' => $schema->primaryKey,
                'name' => $table,
                'rows' => $rows,
                'fields' => $schema->columnNames,
                'offset_total' => ceil($rows/$rowsPerRequest),
            ];
        }
        
        $buildToken = Yii::$app->security->generateRandomString(16);
        
        $build = new ProxyBuild();
        $build->detachBehavior('LogBehavior');
        $build->attributes = [
            'machine_id' => $machine->id,
            'timestamp' => time(),
            'build_token' => sha1($buildToken),
            'config' => Json::encode($config),
            'is_complet' => 0,
            'expiration_time' => time() + $this->module->proxyExpirationTime
        ];
        
        if ($build->save()) {
            return [
                'providerUrl' => Url::base(true) . '/admin/api-admin-proxy/data-provider',
                'requestCloseUrl' => Url::base(true) . '/admin/api-admin-proxy/close',
                'fileProviderUrl' => Url::base(true) . '/admin/api-admin-proxy/file-provider',
                'imageProviderUrl' => Url::base(true) . '/admin/api-admin-proxy/image-provider',
                'buildToken' => $buildToken,
                'config' => $config,
            ];
        }
        
        return $build->getErrors();
    }
public function actionIndex($identifier, $token)
    {
        $machine = ProxyMachine::findOne(['identifier' => $identifier, 'is_deleted' => false]);
        
        if (!$machine) {
            throw new ForbiddenHttpException("Unable to acccess the proxy api.");
        }
        
        if (sha1($machine->access_token) !== $token) {
            throw new ForbiddenHttpException("Unable to acccess the proxy api due to invalid token.");
        }
        
        $rowsPerRequest = $this->module->proxyRowsPerRequest;
        
        $config = [
            'rowsPerRequest' => $rowsPerRequest,
            'tables' => [],
            'storageFilesCount' => StorageFile::find()->count(),
        ];
        
        foreach (Yii::$app->db->schema->tableNames as $table) {
            if (in_array($table, $this->ignoreTables)) {
                continue;
            }
            
            $schema = Yii::$app->db->getTableSchema($table);
            $rows = (new Query())->from($table)->count();
            $config['tables'][$table] = [
                'pks' => $schema->primaryKey,
                'name' => $table,
                'rows' => $rows,
                'fields' => $schema->columnNames,
                'offset_total' => ceil($rows/$rowsPerRequest),
            ];
        }
        
        $buildToken = Yii::$app->security->generateRandomString(16);
        
        $build = new ProxyBuild();
        $build->detachBehavior('LogBehavior');
        $build->attributes = [
            'machine_id' => $machine->id,
            'timestamp' => time(),
            'build_token' => sha1($buildToken),
            'config' => Json::encode($config),
            'is_complet' => 0,
            'expiration_time' => time() + $this->module->proxyExpirationTime
        ];
        
        if ($build->save()) {
            return [
                'providerUrl' => Url::base(true) . '/admin/api-admin-proxy/data-provider',
                'requestCloseUrl' => Url::base(true) . '/admin/api-admin-proxy/close',
                'fileProviderUrl' => Url::base(true) . '/admin/api-admin-proxy/file-provider',
                'imageProviderUrl' => Url::base(true) . '/admin/api-admin-proxy/image-provider',
                'buildToken' => $buildToken,
                'config' => $config,
            ];
        }
        
        return $build->getErrors();
    }
public function actionIndex ( $ identifier , $ token ) { $ machine = ProxyMachine :: findOne ( [ 'identifier' => $ identifier , 'is_deleted' => false ] ) ; if ( ! $ machine ) { throw new ForbiddenHttpException ( "Unable to acccess the proxy api." ) ; } if ( sha1 ( $ machine -> access_token ) !== $ token ) { throw new ForbiddenHttpException ( "Unable to acccess the proxy api due to invalid token." ) ; } $ rowsPerRequest = $ this -> module -> proxyRowsPerRequest ; $ config = [ 'rowsPerRequest' => $ rowsPerRequest , 'tables' => [ ] , 'storageFilesCount' => StorageFile :: find ( ) -> count ( ) , ] ; foreach ( Yii :: $ app -> db -> schema -> tableNames as $ table ) { if ( in_array ( $ table , $ this -> ignoreTables ) ) { continue ; } $ schema = Yii :: $ app -> db -> getTableSchema ( $ table ) ; $ rows = ( new Query ( ) ) -> from ( $ table ) -> count ( ) ; $ config [ 'tables' ] [ $ table ] = [ 'pks' => $ schema -> primaryKey , 'name' => $ table , 'rows' => $ rows , 'fields' => $ schema -> columnNames , 'offset_total' => ceil ( $ rows / $ rowsPerRequest ) , ] ; } $ buildToken = Yii :: $ app -> security -> generateRandomString ( 16 ) ; $ build = new ProxyBuild ( ) ; $ build -> detachBehavior ( 'LogBehavior' ) ; $ build -> attributes = [ 'machine_id' => $ machine -> id , 'timestamp' => time ( ) , 'build_token' => sha1 ( $ buildToken ) , 'config' => Json :: encode ( $ config ) , 'is_complet' => 0 , 'expiration_time' => time ( ) + $ this -> module -> proxyExpirationTime ] ; if ( $ build -> save ( ) ) { return [ 'providerUrl' => Url :: base ( true ) . '/admin/api-admin-proxy/data-provider' , 'requestCloseUrl' => Url :: base ( true ) . '/admin/api-admin-proxy/close' , 'fileProviderUrl' => Url :: base ( true ) . '/admin/api-admin-proxy/file-provider' , 'imageProviderUrl' => Url :: base ( true ) . '/admin/api-admin-proxy/image-provider' , 'buildToken' => $ buildToken , 'config' => $ config , ] ; } return $ build -> getErrors ( ) ; }
Gathers basic informations about the build.

@param string $identifier
@param string $token
@throws ForbiddenHttpException
@return array
Gathers basic informations about the build .