Example #1
0
 public function testReadWrittenFile()
 {
     $reader = new \EasyCSV\Reader(__DIR__ . '/write.csv');
     $results = $reader->getAll();
     $expected = array(array('column1' => '1test1', 'column2' => '1test2ing this out', 'column3' => '1test3'), array('column1' => '2test1', 'column2' => '2test2 ing this out ok', 'column3' => '2test3'));
     $this->assertEquals($expected, $results);
 }
Example #2
0
 public function testReadWrittenBOMFile()
 {
     $reader = new \EasyCSV\Reader(__DIR__ . '/write_bom.csv');
     $results = $reader->getAll();
     $expected = array(array('колонка 1' => 'значение 1', 'колонка 2' => 'значение 2', 'колонка 3' => 'значение 3'), array('колонка 1' => 'значение 4', 'колонка 2' => 'значение 5', 'колонка 3' => 'значение 6'));
     $this->assertEquals($expected, $results);
 }
Example #3
0
 /**
  * Parse data
  *
  * @param array $report Report data
  *
  * @return void
  */
 public function parse($report)
 {
     $data = array();
     $reader = new \EasyCSV\Reader($report['source']['value']);
     while ($row = $reader->getRow()) {
         $data[] = $row;
     }
     $this->setData($data);
 }
Example #4
0
 public function fire($job, $data)
 {
     $file = Config::get('projeter.upload_path') . $data['file'];
     Log::info("Starting to add {$data['target']} to database (File: {$file})");
     $target = new Target();
     $target->name = $data['target'];
     $target->save();
     $reader = new \EasyCSV\Reader($file);
     // There must be a Email field in CSV file
     /*if(!in_array('Email', $reader->getHeaders() ))
     		throw new Exception("Email field not found", 1);*/
     while ($row = $reader->getRow()) {
         Log::info("Adding {$row['Email']} to the target {$data['target']}");
         $mailing = new Mailing();
         $mailing->target()->associate($target);
         $mailing->email = $row['Email'];
         $mailing->save();
     }
     Log::info("Mailing list {$target->name} added to database");
     $job->delete();
 }
Example #5
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $name = $input->getArgument('filename');
     $projectResource = new ProjectResource($this->client);
     $userResource = new UserResource($this->client);
     $memberResource = new MemberResource($this->client);
     $reader = new \EasyCSV\Reader('new_members.csv');
     while ($row = $reader->getRow()) {
         $project = $projectResource->getByCode($row['project_code']);
         // we ned that user for admins, maybe it should be separate field
         $user = $userResource->getOneBy(['username' => $row['username']]);
         if (!$user) {
             print "user '{$row['username']}' not found\n";
         }
         try {
             $res = $memberResource->save(['code' => $row['code'], 'project_id' => $project['id'], 'user_id' => $user['id'], 'permission_type_code' => $row['permission_type_code']]);
         } catch (Exception $e) {
             print "Error importing member {$row['code']}:" . $e->getMessage() . "\n";
         }
     }
     $output->writeln($text);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $filename = $input->getArgument('filename');
     $serverCode = $input->getOption('server-code');
     $timezoneId = $input->getOption('timezone-id');
     $projectCode = $input->getOption('project-code');
     $userResource = new UserResource($this->client);
     /** @type MemberResource $memberResource */
     $memberResource = new MemberResource($this->client);
     $projectResource = new ProjectResource($this->client);
     /** @type ProjectResource $resource */
     $resource = new ProjectResource($this->client);
     $reader = new \EasyCSV\Reader($filename, 'r', true);
     while ($row = $reader->getRow()) {
         //code,name,description,timezone_id
         $code = $row['code'];
         if ($projectCode && $code != $projectCode) {
             continue;
         }
         $params = [];
         if ($project = $resource->getOneBy(['code' => $code])) {
             $params['id'] = $project['id'];
         }
         try {
             /*
             $res = $resource->save(
                 array_merge(
                     $params,
                     [
                         'title'                  => $name = $row['name'],
                         'code'                   => $code,
                         'timezone_id'            => $timezoneId,
                         'description'            => $name." Project",
                         'background_server_code' => $serverCode,
                     ]
                 )
             );
             */
         } catch (\Exception $e) {
             printf("Error saving project: %s\n", $e->getMessage());
             printf("Project {$code} already exists\n");
         }
         $project = $projectResource->getByCode($code);
         $res = $resource->addModule($code, 'turk');
         $staffAdmins = ['tac', 'ho449'];
         try {
             foreach (array_merge([$code], $staffAdmins) as $idx => $username) {
                 $user = $userResource->getOneBy(['username' => $username]);
                 if (!$user) {
                     print "user '{$username}' not found\n";
                     continue;
                 }
                 $params = ['code' => $username, 'project_id' => $project['id'], 'user_id' => $user['id'], 'permission_type_code' => 'owner', 'enrollment_status_code' => 'notenrolled'];
                 $member = $memberResource->getOneBy(['code' => $username, 'project_id' => $project['id']]);
                 if ($member) {
                     $output->writeln("<error>Member '{$username}' already exists for project " . $project['code'] . "</error>");
                     continue;
                 }
                 print "Saving member '{$username}' for project " . $project['code'] . "\n";
                 $res = $memberResource->save($params);
             }
         } catch (Exception $e) {
             var_dump($params);
             $output->writeln("<error>Error importing member: {$e->getMessage()}</error>");
         }
     }
 }