public function testWrapFromPath() { $file = dirname(dirname(dirname(__DIR__))) . DS . 'data' . DS . 'CsvMigrations' . DS . 'migrations' . DS . 'Foo' . DS . 'migration.csv'; $parser = new MigrationParser(); $result = $parser->wrapFromPath($file); $this->assertTrue(is_array($result), "Parser returned a non-array"); $this->assertFalse(empty($result), "Parser returned empty result"); }
/** * Apply changes from the CSV file * * @param string $path Path to the CSV file * @return void */ protected function _handleCsv($path = '') { $tableName = Inflector::pluralize(Inflector::classify($this->_table->getName())); if ('' === trim($path)) { $pathFinder = new MigrationPathFinder(); $path = $pathFinder->find($tableName); } $parser = new MigrationParser(); $csvData = $parser->wrapFromPath($path); $csvData = array_merge($csvData, $this->_requiredFields); $tableFields = $this->_getTableFields(); if (empty($tableFields)) { $this->_createFromCsv($csvData); } else { $this->_updateFromCsv($csvData, $tableFields); } }
/** * Get all modules data. * * @return array Modules, fields and fields types. */ protected function _csvData() { $result = []; $path = Configure::readOrFail('CsvMigrations.migrations.path'); $csvFiles = $this->_getCsvFiles($path); /* covers case where CsvMigration configuration files reside in a plugin. */ $plugin = $this->_getPluginNameFromPath($path); if (is_null($plugin)) { /* covers case where CsvMigration model and controller reside in a plugin (even if configuration files reside in the APP level). */ $plugin = $this->_getPluginNameFromRegistryAlias(); } $parser = new MigrationParser(); foreach ($csvFiles as $csvModule => $paths) { if (!is_null($plugin)) { $csvModule = $plugin . '.' . $csvModule; } foreach ($paths as $path) { $result[$csvModule] = $parser->wrapFromPath($path); } } return $result; }
/** * Method that retrieves and returns csv migration fields. * * @param Request $request Request object * @return array */ protected function _getMigrationFields(Request $request) { $result = []; try { $pathFinder = new MigrationPathFinder(); $path = $pathFinder->find($request->controller); $parser = new MigrationParser(); $result = $parser->wrapFromPath($path); } catch (InvalidArgumentException $e) { Log::error($e); } return $result; }