application/modules/g/controllers/ContentController.php
public function importAction() {
        $memLim = ini_get('memory_limit');
        ini_set('memory_limit', '2G');
        set_time_limit(0); // No time limit

        $params = new Garp_Util_Configuration($this->getRequest()->getParams());
        $params->obligate('datafile')
            ->obligate('model')
            ->setDefault('firstRow', 0)
            ->setDefault('ignoreErrors', false);
        $importer = Garp_Content_Import_Factory::getImporter($params['datafile']);
        $success = false;
        if (isset($params['mapping'])) {
            $mapping = Zend_Json::decode($params['mapping']);

            $className = Garp_Content_Api::modelAliasToClass($params['model']);
            $model = new $className();
            $model->setCmsContext(true);
            $response = array();
            try {
                $success    = !!$importer->save(
                    $model, $mapping, array(
                    'firstRow' => $params['firstRow'],
                    'ignoreErrors' => $params['ignoreErrors'],
                    )
                );
            } catch (Exception $e) {
                $response['message'] = $e->getMessage();
            }

            if ($success) {
                // cleanup input file
                $gf = new Garp_File();
                $gf->remove($params['datafile']);
            }

            $response['success'] = $success;
            $this->view->response = $response;
        } else {
            $std = new stdClass();
            $std->success = true;
            $std->data = $importer->getSampleData();
            $this->view->response = $std;
        }
        ini_set('memory_limit', $memLim);
        $this->_helper->layout->setLayout('json');
        $this->renderScript('content/call.phtml');
    }
public function importAction() {
        $memLim = ini_get('memory_limit');
        ini_set('memory_limit', '2G');
        set_time_limit(0); // No time limit

        $params = new Garp_Util_Configuration($this->getRequest()->getParams());
        $params->obligate('datafile')
            ->obligate('model')
            ->setDefault('firstRow', 0)
            ->setDefault('ignoreErrors', false);
        $importer = Garp_Content_Import_Factory::getImporter($params['datafile']);
        $success = false;
        if (isset($params['mapping'])) {
            $mapping = Zend_Json::decode($params['mapping']);

            $className = Garp_Content_Api::modelAliasToClass($params['model']);
            $model = new $className();
            $model->setCmsContext(true);
            $response = array();
            try {
                $success    = !!$importer->save(
                    $model, $mapping, array(
                    'firstRow' => $params['firstRow'],
                    'ignoreErrors' => $params['ignoreErrors'],
                    )
                );
            } catch (Exception $e) {
                $response['message'] = $e->getMessage();
            }

            if ($success) {
                // cleanup input file
                $gf = new Garp_File();
                $gf->remove($params['datafile']);
            }

            $response['success'] = $success;
            $this->view->response = $response;
        } else {
            $std = new stdClass();
            $std->success = true;
            $std->data = $importer->getSampleData();
            $this->view->response = $std;
        }
        ini_set('memory_limit', $memLim);
        $this->_helper->layout->setLayout('json');
        $this->renderScript('content/call.phtml');
    }
public function importAction ( ) { $ memLim = ini_get ( 'memory_limit' ) ; ini_set ( 'memory_limit' , '2G' ) ; set_time_limit ( 0 ) ; // No time limit $ params = new Garp_Util_Configuration ( $ this -> getRequest ( ) -> getParams ( ) ) ; $ params -> obligate ( 'datafile' ) -> obligate ( 'model' ) -> setDefault ( 'firstRow' , 0 ) -> setDefault ( 'ignoreErrors' , false ) ; $ importer = Garp_Content_Import_Factory :: getImporter ( $ params [ 'datafile' ] ) ; $ success = false ; if ( isset ( $ params [ 'mapping' ] ) ) { $ mapping = Zend_Json :: decode ( $ params [ 'mapping' ] ) ; $ className = Garp_Content_Api :: modelAliasToClass ( $ params [ 'model' ] ) ; $ model = new $ className ( ) ; $ model -> setCmsContext ( true ) ; $ response = array ( ) ; try { $ success = ! ! $ importer -> save ( $ model , $ mapping , array ( 'firstRow' => $ params [ 'firstRow' ] , 'ignoreErrors' => $ params [ 'ignoreErrors' ] , ) ) ; } catch ( Exception $ e ) { $ response [ 'message' ] = $ e -> getMessage ( ) ; } if ( $ success ) { // cleanup input file $ gf = new Garp_File ( ) ; $ gf -> remove ( $ params [ 'datafile' ] ) ; } $ response [ 'success' ] = $ success ; $ this -> view -> response = $ response ; } else { $ std = new stdClass ( ) ; $ std -> success = true ; $ std -> data = $ importer -> getSampleData ( ) ; $ this -> view -> response = $ std ; } ini_set ( 'memory_limit' , $ memLim ) ; $ this -> _helper -> layout -> setLayout ( 'json' ) ; $ this -> renderScript ( 'content/call.phtml' ) ; }
Import content from various formats.
This action has two states;
- first a datafile is uploaded. The user is presented with a mapping interface
where they have to map columns in the datafile to columns in the database.
- then this URL is called again with the selected mapping, and the columns are
mapped and inserted into the database.

@return Void
Import content from various formats . This action has two states ; - first a datafile is uploaded . The user is presented with a mapping interface where they have to map columns in the datafile to columns in the database . - then this URL is called again with the selected mapping and the columns are mapped and inserted into the database .