diff --git a/dependency/csv/Csv.php b/dependency/csv/Csv.php index 0f8b07e9ed4e8ec5bd985460c2a1cc6c178ac87f..dce9ddf295631ca21df34da5576b23acbca8c2da 100644 --- a/dependency/csv/Csv.php +++ b/dependency/csv/Csv.php @@ -30,6 +30,13 @@ class Csv * @param resource $filename */ public function read($filename, $className, $messageType = false, $delimiter = ',', $enclosure = '"', $escape = '\\') + { + $handler = fopen($filename, 'r'); + + return $this->readStream($handler, $className, $messageType, $delimiter, $enclosure, $escape); + } + + public function readStream($handler, $className, $messageType = false, $delimiter = ',', $enclosure = '"', $escape = '\\') { if ($messageType) { $class = \laabs::getMessage($className); @@ -37,8 +44,6 @@ class Csv $class = \laabs::getClass($className); } - $handler = fopen($filename, 'r'); - $header = fgetcsv($handler, 0, $delimiter, $enclosure, $escape); $properties = $this->getPropertiesFromHeader($header, $class); @@ -57,6 +62,7 @@ class Csv fclose($handler); return $collection; + } protected function getPropertiesFromHeader($header, $class) diff --git a/src/bundle/auth/Controller/role.php b/src/bundle/auth/Controller/role.php index c4d13528e092b425b40d2468cc1520e1b0f3da78..ad3b23154d1c621871b8d509c78140a5a47b562f 100755 --- a/src/bundle/auth/Controller/role.php +++ b/src/bundle/auth/Controller/role.php @@ -443,9 +443,7 @@ class role } } - $filename = \laabs\tempnam(); - file_put_contents($filename, $data); - $roles = $this->csv->read($filename, 'auth/roleImportExport', true); + $roles = $this->csv->readStream($data, 'auth/roleImportExport', true); foreach ($roles as $key => $role) { if ($isReset || !$this->sdoFactory->exists('auth/role', $role->roleId) diff --git a/src/bundle/auth/Controller/serviceAccount.php b/src/bundle/auth/Controller/serviceAccount.php index b9c297fc5829c044278bd39ce6c66b8a11834405..195a3d855654e400107cb028fa761d7656c7881e 100755 --- a/src/bundle/auth/Controller/serviceAccount.php +++ b/src/bundle/auth/Controller/serviceAccount.php @@ -545,16 +545,14 @@ class serviceAccount /** * Import Service account function and create or update them * - * @param array $data Array of serviceAccountImportExort Message - * @param boolean $isReset Reset tables or not + * @param resource $data Array of serviceAccountImportExport Message + * @param boolean $isReset Reset tables or not * - * @return boolean Success of operation or not + * @return boolean Success of operation or not */ public function import($data, $isReset = false) { - $filename = \laabs\tempnam(); - file_put_contents($filename, $data); - $services = $this->csv->read($filename, 'auth/serviceAccountImportExport', $messageType = true); + $services = $this->csv->readStream($data, 'auth/serviceAccountImportExport', $messageType = true); $organizationController = \laabs::newController('organization/organization'); $transactionControl = !$this->sdoFactory->inTransaction(); diff --git a/src/bundle/auth/Controller/userAccount.php b/src/bundle/auth/Controller/userAccount.php index 6069724b515b4960716daf9d34a50216ad3ff25f..e6057cfd2ef08e1068a702c170983bb96b9dd10d 100755 --- a/src/bundle/auth/Controller/userAccount.php +++ b/src/bundle/auth/Controller/userAccount.php @@ -833,10 +833,10 @@ class userAccount /** * Import User account function and create or update them * - * @param array $data Array of userAccountImportExort Message - * @param boolean $isReset Reset tables or not + * @param resource $data Array of userAccountImportExport Message + * @param boolean $isReset Reset tables or not * - * @return boolean Success of operation or not + * @return boolean Success of operation or not */ public function import($data, $isReset = false) { @@ -844,9 +844,7 @@ class userAccount $organizationController = \laabs::newController('organization/organization'); $roleController = \laabs::newController('auth/role'); - $filename = \laabs\tempnam(); - file_put_contents($filename, $data); - $users = $this->csv->read($filename, 'auth/userAccountImportExport', $messageType = true); + $users = $this->csv->readStream($data, 'auth/userAccountImportExport', $messageType = true); $transactionControl = !$this->sdoFactory->inTransaction(); @@ -957,7 +955,7 @@ class userAccount } } - if (!hasSuperAdmin) { + if (!$hasSuperAdmin) { throw new \Exception("Csv must have at least one superadmin"); } } diff --git a/src/bundle/auth/roleInterface.php b/src/bundle/auth/roleInterface.php index f1247829b41cba521ff3616ef3eae7a672726eff..ee8408d74e01c1fdd3106eb9e53157c458c4b12c 100755 --- a/src/bundle/auth/roleInterface.php +++ b/src/bundle/auth/roleInterface.php @@ -51,8 +51,8 @@ interface roleInterface public function readExport($limit = null); /** - * @param string $data Data base64 encoded or not - * @param boolean $isReset Reset tables or not + * @param resource $data Data base64 encoded or not + * @param boolean $isReset Reset tables or not * * @action auth/role/import * diff --git a/src/bundle/auth/serviceAccountInterface.php b/src/bundle/auth/serviceAccountInterface.php index d8469ec421422e7b2e017d0bfafc47d454f1fc2c..ed11e11c291945f46c3521e5e19e2f821d9478ff 100755 --- a/src/bundle/auth/serviceAccountInterface.php +++ b/src/bundle/auth/serviceAccountInterface.php @@ -126,8 +126,8 @@ interface serviceAccountInterface public function readQuery_query_($query = null); /** - * @param string $data Data base64 encoded or not - * @param boolean $isReset Reset tables or not + * @param resource $data Data base64 encoded or not + * @param boolean $isReset Reset tables or not * * @action auth/serviceAccount/import * diff --git a/src/bundle/auth/userAccountInterface.php b/src/bundle/auth/userAccountInterface.php index efa989dfd52c43cd0dc7dbdf0f887c78a5cc9cde..e54e1250f6df26f3b479c7718ec733c65dab0713 100755 --- a/src/bundle/auth/userAccountInterface.php +++ b/src/bundle/auth/userAccountInterface.php @@ -245,7 +245,7 @@ interface userAccountInterface public function updatePasswordchangerequest_userAccountId_(); /** - * @param string $data Data base64 encoded or not + * @param resource $data Data base64 encoded or not * @param boolean $isReset Reset tables or not * * @action auth/userAccount/import diff --git a/src/bundle/organization/Controller/organization.php b/src/bundle/organization/Controller/organization.php index de07cc293b63faa9ca3185a5aaf9592eedb16384..c23ad569502d6d0956e421bf00ab76d734dbaccc 100755 --- a/src/bundle/organization/Controller/organization.php +++ b/src/bundle/organization/Controller/organization.php @@ -1620,16 +1620,15 @@ class organization /** * Import organization and create or update them * - * @param array $data Array of serviceAccountImportExort Message - * @param boolean $isReset Reset tables or not + * @param resource $data Array of serviceAccountImportExport Message + * @param boolean $isReset Reset tables or not * * @return boolean Success of operation or not */ public function import($data, $isReset = false) { - $filename = \laabs\tempnam(); - file_put_contents($filename, $data); - $organizations = $this->csv->read($filename, 'organization/organizationImportExport', $messageType = true); + + $organizations = $this->csv->readStream($data, 'organization/organizationImportExport', $messageType = true); $transactionControl = !$this->sdoFactory->inTransaction(); if ($transactionControl) { diff --git a/src/bundle/organization/organizationInterface.php b/src/bundle/organization/organizationInterface.php index c4d613e14a03927df39f018fb30a85c2e3a7009c..9cb7649a9118d7d1d55ae3fe86e703bf6751b015 100755 --- a/src/bundle/organization/organizationInterface.php +++ b/src/bundle/organization/organizationInterface.php @@ -346,8 +346,8 @@ interface organizationInterface public function read_orgId_ChangeStatus_status_(); /** - * @param string $data Data base64 encoded or not - * @param boolean $isReset Reset tables or not + * @param resource $data Data base64 encoded or not + * @param boolean $isReset Reset tables or not * * @action organization/organization/import * diff --git a/src/bundle/recordsManagement/Controller/archivalProfile.php b/src/bundle/recordsManagement/Controller/archivalProfile.php index 8b99b5dcafd9916b3674c085f81fe8028e8e1de5..9bd8654cbdcc04d8722307ba88f69cee7fafeec9 100755 --- a/src/bundle/recordsManagement/Controller/archivalProfile.php +++ b/src/bundle/recordsManagement/Controller/archivalProfile.php @@ -511,9 +511,7 @@ class archivalProfile } } - $filename = \laabs\tempnam(); - file_put_contents($filename, $data); - $archivalProfiles = $this->csv->read($filename, 'recordsManagement/archivalProfileImportExport', true); + $archivalProfiles = $this->csv->readStream($data, 'recordsManagement/archivalProfileImportExport', true); $archivalProfileContents = []; $archivalProfilesReferences = []; foreach ($archivalProfiles as $key => $archivalProfile) { diff --git a/src/bundle/recordsManagement/Controller/descriptionField.php b/src/bundle/recordsManagement/Controller/descriptionField.php index 59c3996abdea5aafebc195fd187ea46ea82855f2..c9ce0b087de607776ace3614f9bdfa303ee71679 100755 --- a/src/bundle/recordsManagement/Controller/descriptionField.php +++ b/src/bundle/recordsManagement/Controller/descriptionField.php @@ -282,9 +282,7 @@ class descriptionField } } - $filename = \laabs\tempnam(); - file_put_contents($filename, $data); - $descriptionFields = $this->csv->read($filename, 'recordsManagement/descriptionField', $messageType = false); + $descriptionFields = $this->csv->readStream($data, 'recordsManagement/descriptionField', $messageType = false); foreach ($descriptionFields as $key => $descriptionField) { if (is_null($descriptionField->name)) { throw new \core\Exception\BadRequestException("Name cannot be null"); diff --git a/src/bundle/recordsManagement/Controller/retentionRule.php b/src/bundle/recordsManagement/Controller/retentionRule.php index 2826549f091916d0e5124f58c6c37203899ca1bb..08c45b0819cc986081b477b9b63e416c2b205084 100755 --- a/src/bundle/recordsManagement/Controller/retentionRule.php +++ b/src/bundle/recordsManagement/Controller/retentionRule.php @@ -194,9 +194,7 @@ class retentionRule } } - $filename = \laabs\tempnam(); - file_put_contents($filename, $data); - $retentionRules = $this->csv->read($filename, 'recordsManagement/retentionRule', true); + $retentionRules = $this->csv->readStream($data, 'recordsManagement/retentionRule', true); foreach ($retentionRules as $key => $retentionRule) { if ($isReset diff --git a/src/bundle/recordsManagement/archivalProfileInterface.php b/src/bundle/recordsManagement/archivalProfileInterface.php index 5d3f47500736ed3ea79e9abf0163bfa0ebfec6db..bbd7dd9d3e165a9a352ca3941b6429d002a13eb4 100755 --- a/src/bundle/recordsManagement/archivalProfileInterface.php +++ b/src/bundle/recordsManagement/archivalProfileInterface.php @@ -54,8 +54,8 @@ interface archivalProfileInterface public function readExport($limit = null); /** - * @param string $data Data base64 encoded or not - * @param boolean $isReset Reset tables or not + * @param resource $data Data base64 encoded or not + * @param boolean $isReset Reset tables or not * * @action recordsManagement/archivalProfile/import * diff --git a/src/bundle/recordsManagement/descriptionFieldInterface.php b/src/bundle/recordsManagement/descriptionFieldInterface.php index ab7cc0d4c6e118ed3864bfa2e2a87c3b60a9156f..5f84ee06ec9a0408affffa7b28546dcb4052646c 100755 --- a/src/bundle/recordsManagement/descriptionFieldInterface.php +++ b/src/bundle/recordsManagement/descriptionFieldInterface.php @@ -75,8 +75,8 @@ interface descriptionFieldInterface public function delete_name_(); /** - * @param string $data Data base64 encoded or not - * @param boolean $isReset Reset tables or not + * @param resource $data Data base64 encoded or not + * @param boolean $isReset Reset tables or not * * @action recordsManagement/descriptionField/import * diff --git a/src/bundle/recordsManagement/retentionRuleInterface.php b/src/bundle/recordsManagement/retentionRuleInterface.php index 06663178e1cd73c2bea2fb336747bacc954fcfa3..852f1865b19d386d959684f971564372f8ff0dfa 100755 --- a/src/bundle/recordsManagement/retentionRuleInterface.php +++ b/src/bundle/recordsManagement/retentionRuleInterface.php @@ -53,8 +53,8 @@ interface retentionRuleInterface public function readExport($limit = null); /** - * @param string $data Data base64 encoded or not - * @param boolean $isReset Reset tables or not + * @param resource $data Data base64 encoded or not + * @param boolean $isReset Reset tables or not * * @action recordsManagement/retentionRule/import * diff --git a/src/presentation/maarchRM/Resources/view/importExport/index.html b/src/presentation/maarchRM/Resources/view/importExport/index.html index 24a6a000cf3fc12b7fbdf1dfd61c490c0db6a6e6..2bdc7c109023b8d3c286e8c4a3a8c0c9ce54da0b 100644 --- a/src/presentation/maarchRM/Resources/view/importExport/index.html +++ b/src/presentation/maarchRM/Resources/view/importExport/index.html @@ -182,16 +182,11 @@ return; } - var data = { - 'data': file[0].handler, - 'isReset' : isReset - }; - ajax($('#exportContainer'), { - url: '/import/' + referentiel, + url: '/import/' + referentiel + '?isReset=' + isReset, type: 'POST', - data: JSON.stringify(data), - contentType: 'application/json', + data: file[0].handler, + contentType: 'text/csv', success: function (response) { gritter.show($("#file_success").text(), 'true'); }, diff --git a/src/presentation/maarchRM/UserStory/import/importArchivalProfileInterface.php b/src/presentation/maarchRM/UserStory/import/importArchivalProfileInterface.php index 51ee025913af2cc4850b290f79ddb489dc8bddb0..ef0f44102a4286b71d38a555927ee4d231e3b594 100644 --- a/src/presentation/maarchRM/UserStory/import/importArchivalProfileInterface.php +++ b/src/presentation/maarchRM/UserStory/import/importArchivalProfileInterface.php @@ -7,8 +7,8 @@ interface importArchivalProfileInterface /** * Import a csv file with archival profile informations * - * @param string $data Data base64 encoded or not in proper format - * @param boolean $isReset Reset tables or not + * @param resource $data Data base64 encoded or not in proper format + * @param boolean $isReset Reset tables or not * * @uses recordsManagement/archivalProfile/createImport * diff --git a/src/presentation/maarchRM/UserStory/import/importDescriptionFieldInterface.php b/src/presentation/maarchRM/UserStory/import/importDescriptionFieldInterface.php index 64983b55ceeb9a4279b90b11e690d4c4a3d086ff..b371e2a27845dca027b9ef482f99e9357ce306bf 100644 --- a/src/presentation/maarchRM/UserStory/import/importDescriptionFieldInterface.php +++ b/src/presentation/maarchRM/UserStory/import/importDescriptionFieldInterface.php @@ -7,8 +7,8 @@ interface importDescriptionFieldInterface /** * Import a csv file with description field informations * - * @param string $data Data base64 encoded or not in proper format - * @param boolean $isReset Reset tables or not + * @param resource $data Data base64 encoded or not in proper format + * @param boolean $isReset Reset tables or not * * @uses recordsManagement/descriptionField/createImport * diff --git a/src/presentation/maarchRM/UserStory/import/importOrganizationInterface.php b/src/presentation/maarchRM/UserStory/import/importOrganizationInterface.php index 551e96ddec8b649abbac9df6d50b865cb1c977fe..9492306f792ec58c2d32eee29906cc7b1181ed1d 100644 --- a/src/presentation/maarchRM/UserStory/import/importOrganizationInterface.php +++ b/src/presentation/maarchRM/UserStory/import/importOrganizationInterface.php @@ -7,8 +7,8 @@ interface importOrganizationInterface /** * Import a csv file with organization informations * - * @param string $data Data base64 encoded or not in proper format - * @param boolean $isReset Reset tables or not + * @param resource $data Data base64 encoded or not in proper format + * @param boolean $isReset Reset tables or not * * @uses organization/organization/createImport * diff --git a/src/presentation/maarchRM/UserStory/import/importRetentionRuleInterface.php b/src/presentation/maarchRM/UserStory/import/importRetentionRuleInterface.php index c52ed5a927a338df63afca423e7b021ef6192a01..1901239f2d6c24f93859674bb667ee6dfa637f7f 100644 --- a/src/presentation/maarchRM/UserStory/import/importRetentionRuleInterface.php +++ b/src/presentation/maarchRM/UserStory/import/importRetentionRuleInterface.php @@ -7,8 +7,8 @@ interface importRetentionRuleInterface /** * Import a csv file with retention rules informations * - * @param string $data Data base64 encoded or not in proper format - * @param boolean $isReset Reset tables or not + * @param resource $data Data base64 encoded or not in proper format + * @param boolean $isReset Reset tables or not * * @uses recordsManagement/retentionRule/createImport * diff --git a/src/presentation/maarchRM/UserStory/import/importRoleInterface.php b/src/presentation/maarchRM/UserStory/import/importRoleInterface.php index c2becc96372fb8a7b4e47786234bcf68b328bdb3..7377d76b0518de4f07be4fa8aa65fead7bc8f604 100644 --- a/src/presentation/maarchRM/UserStory/import/importRoleInterface.php +++ b/src/presentation/maarchRM/UserStory/import/importRoleInterface.php @@ -7,8 +7,8 @@ interface importRoleInterface /** * Import a csv file with role informations * - * @param string $data Data base64 encoded or not in proper format - * @param boolean $isReset Reset tables or not + * @param resource $data Data base64 encoded or not in proper format + * @param boolean $isReset Reset tables or not * * @uses auth/role/createImport * diff --git a/src/presentation/maarchRM/UserStory/import/importServiceAccountInterface.php b/src/presentation/maarchRM/UserStory/import/importServiceAccountInterface.php index 90daa6f279c6c60678ff00aa13cb19889b1409c3..a073d8e9dd73c144d4844ba405e23ade5b633e2e 100644 --- a/src/presentation/maarchRM/UserStory/import/importServiceAccountInterface.php +++ b/src/presentation/maarchRM/UserStory/import/importServiceAccountInterface.php @@ -7,8 +7,8 @@ interface importServiceAccountInterface /** * Import a csv file with service account informations * - * @param string $data Data base64 encoded or not in proper format - * @param boolean $isReset Reset tables or not + * @param resource $data Data base64 encoded or not in proper format + * @param boolean $isReset Reset tables or not * * @uses auth/serviceAccount/createImport * diff --git a/src/presentation/maarchRM/UserStory/import/importUserAccountInterface.php b/src/presentation/maarchRM/UserStory/import/importUserAccountInterface.php index 84ac83dafc59ff6e0229189a3252c1772f5c0be5..a8bc87823647c9f7a5c560b89a2e420b428abf2e 100644 --- a/src/presentation/maarchRM/UserStory/import/importUserAccountInterface.php +++ b/src/presentation/maarchRM/UserStory/import/importUserAccountInterface.php @@ -7,8 +7,8 @@ interface importUserAccountInterface /** * Import a csv file with user account informations * - * @param string $data Data base64 encoded or not in proper format - * @param boolean $isReset Reset tables or not + * @param resource $data Data base64 encoded or not in proper format + * @param boolean $isReset Reset tables or not * * @uses auth/userAccount/createImport *