Syntax error when creating PHP function

0

Good day, I have this problem when running a function in PHP, if someone can help me, I thank you in advance

   public function actionIndex()
    {
        // ejecución de la tarea de etl
        $job = new Job();
        Job::start()
        // datos a extraer
        ->extract('table', 'user'); 
        $options = ['columns' => ['user_id','user_name','user_real_name']];        
        [
            'connection' => 'mysql' // Base de datos de donde obtendre los datos, si no viene seteado se utiliza el valor que tiene el campo 'default'
        ],
        // transformacion a aplicar a los datos
        ->transform('trim', ['columns' => ['codigo', 'nombreusuario', 'nombre']])
        // donde cargare los datos
        ->load('table', 'usuario_dimension_wikieam', [
            'connection' => 'pgsql' // Base de datos a donde voy a insertar los datos
        ]);
    }

This is the class where the function is

class EtlController extends Controller
{

    public function actionEtl(){
        return $this->render('index',[]);
    }


    public $file;
    public function init()
    {
        Etl::config([
            'path' => '/path/to/etl/files',
            'database' => [
                // Base de datos a utilizar
                'default' => 'mysql',

                'connections' => [

                    'mysql' => [
                        'driver' => 'mysql',
                        'host' => 'localhost',
                        'port' => '3306',
                        'database' => 'wikieam',
                        'username' => 'root',
                        'password' => '1234',
                        'charset' => 'utf8',
                        'collation' => 'utf8_unicode_ci',
                    ],

                    'mysql' => [
                        'driver' => 'mysql',
                        'host' => 'localhost',
                        'port' => '3306',
                        'database' => 'tempwikieam',
                        'username' => 'root',
                        'password' => '1234',
                        'charset' => 'utf8',
                        'collation' => 'utf8_unicode_ci',
                    ],

                    'pgsql' => [
                        'driver' => 'pgsql',
                        'host' => 'localhost',
                        'port' => '5432',
                        'database' => 'dwmediawiki',
                        'username' => 'postgres',
                        'password' => 'admin',
                        'charset' => 'utf8',
                        'schema' => 'public',
                    ],

                ],

            ],

        ]);
    }
    public function options($actionID)
    {
        return ['file'];
    }

    public function optionAliases()
    {
        return ['f' => 'file'];
    }

    function actionIndex()
    {
        // ejecución de la tarea de etl
        $job = new Job();
        Job::start()
        // datos a extraer
        ->extract('table', 'user'); 
        $options = ['columns' => ['user_id','user_name','user_real_name']];        
        [
            'connection' => 'mysql' // Base de datos de donde obtendre los datos, si no viene seteado se utiliza el valor que tiene el campo 'default'
        ]
        // transformacion a aplicar a los datos
        ->transform('trim', ['columns' => ['codigo', 'nombreusuario', 'nombre']])
        // donde cargare los datos
        ->load('table', 'usuario_dimension_wikieam', [
            'connection' => 'pgsql' // Base de datos a donde voy a insertar los datos
        ]);
    }

    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['POST'],
                ],
            ],
        ];
    }

//    /**
//     * Lists all etl models.
//     * @return mixed
//     */
//    public function actionIndex()
//    {
//        $dataProvider = new ActiveDataProvider([
//            'query' => etl::find(),
//        ]);
//
//        return $this->render('index', [
//            'dataProvider' => $dataProvider,
//        ]);
//    }

    /**
     * Displays a single etl model.
     * @param integer $id
     * @return mixed
     */
    public function actionView($id)
    {
        return $this->render('view', [
            'model' => $this->findModel($id),
        ]);
    }

    /**
     * Creates a new etl model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
    public function actionCreate()
    {
        $model = new etl();

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['view', 'id' => $model->idetl]);
        } else {
            return $this->render('create', [
                'model' => $model,
            ]);
        }
    }

    /**
     * Updates an existing etl model.
     * If update is successful, the browser will be redirected to the 'view' page.
     * @param integer $id
     * @return mixed
     */
    public function actionUpdate($id)
    {
        $model = $this->findModel($id);

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['view', 'id' => $model->idetl]);
        } else {
            return $this->render('update', [
                'model' => $model,
            ]);
        }
    }

    /**
     * Deletes an existing etl model.
     * If deletion is successful, the browser will be redirected to the 'index' page.
     * @param integer $id
     * @return mixed
     */
    public function actionDelete($id)
    {
        $this->findModel($id)->delete();

        return $this->redirect(['index']);
    }

    /**
     * Finds the etl model based on its primary key value.
     * If the model is not found, a 404 HTTP exception will be thrown.
     * @param integer $id
     * @return etl the loaded model
     * @throws NotFoundHttpException if the model cannot be found
     */
    protected function findModel($id)
    {
        if (($model = etl::findOne($id)) !== null) {
            return $model;
        } else {
            throw new NotFoundHttpException('The requested page does not exist.');
        }
    }
}
    
asked by Sebastian Salazar 10.03.2018 в 05:08
source

1 answer

2

The problem is that you are defining the variable $options in the middle of a sequence of operations and that is breaking everything.

The solution is to move $options out of the sequence of instructions and to correct the parameters of extract (to put them as you have put them in this other question you asked ). With this pair of changes, that problem should be solved:

    // movemos options aqui arriba
    $options = ['columns' => ['user_id','user_name','user_real_name']];  

    // ejecución de la tarea de etl
    $job = new Job();
    Job::start()
    // datos a extraer
    ->extract('table', 'user', [
        'connection' => 'mysql' // Base de datos de donde obtendre los datos, si no viene seteado se utiliza el valor que tiene el campo 'default'
    ])
    // transformacion a aplicar a los datos
    ->transform('trim', ['columns' => ['codigo', 'nombreusuario', 'nombre']])
    // donde cargare los datos
    ->load('table', 'usuario_dimension_wikieam', [
        'connection' => 'pgsql' // Base de datos a donde voy a insertar los datos
    ]);
    
answered by 10.03.2018 / 05:57
source