public function addPicName() { $x = 0; $em = $this->em; $site = $this->site; $zipPicRoot = $this->uploadPath . "/pics/"; $baseRoot = $this->getContainer()->get('kernel')->getRootDir() . '/../'; chdir($zipPicRoot); $userName = $this->dialog->ask($this->output, 'Please Enter The User Name To Upload As (admin)', 'admin'); $user = $this->em->getRepository('SudouxCmsUserBundle:User')->loadUserByUsername($userName); $officers = $this->em->getRepository('SudouxMortgageBundle:LoanOfficer')->findAllBySite($site); foreach ($officers as $lo) { $x++; $counter = 0; $size = 0; $photoData = NULL; $loName = str_replace(" ", "_", $lo->getFullName()); $globResults = glob("{$zipPicRoot}{$loName}.*"); if ($globResults) { $this->output->writeln(PHP_EOL . "{$x}.) Picture Found for LOSid - {$loName}" . PHP_EOL); $ext = pathinfo($globResults[0], PATHINFO_EXTENSION); $picName = "{$loName}.{$ext}"; $existingPhoto = $lo->getOfficerPhoto(); if (isset($existingPhoto)) { $em->remove($existingPhoto); } $openFileName = $zipPicRoot . $picName; $savePath = realpath($baseRoot) . "/web/uploads/sites/" . $site->getId() . "/public/"; $MIMEtype = mime_content_type($openFileName); $this->output->writeln("Current Name: " . $picName); $this->output->writeln("SavePath: " . $savePath); $this->output->writeln("MIME Type: " . $MIMEtype); while (file_exists($savePath . $picName)) { $picName = $loName . "_{$counter}." . $ext; $counter++; $this->output->writeln("File Name Exists - New Name: <fg=blue>{$picName}</fg=blue>"); } rename($openFileName, $savePath . $picName); $photo = new File(); $size = filesize($savePath . $picName); $photo->setPath("uploads/sites/" . $site->getId() . "/public/" . $picName); $photo->setFilesize($size); $photo->setName($lo->getFullName()); $photo->setUser($user); $photo->setMimeType($MIMEtype); $photo->setSite($site); $this->em->persist($photo); $lo->setOfficerPhoto($photo); $this->em->persist($lo); $this->output->writeln($lo->getFullName() . " - photo has been updated"); } else { $this->output->writeln(PHP_EOL . "{$x}.) No photo found for " . $lo->getFullName()); } } $em->flush(); $this->output->writeln(PHP_EOL . "<fg=yellow> The Following Pictures Were Unable To Be Set as Officer Photos - </fg=yellow>"); chdir($zipPicRoot); passthru("ls"); }
protected function importPics() { $x = 0; $counter = 0; $zipPicRoot = $this->uploadPath . "/branches/"; $baseRoot = $this->getContainer()->get('kernel')->getRootDir() . '/../'; $this->output->writeln("Available Files: " . PHP_EOL); chdir($this->uploadPath . "/branches"); passthru("ls *.csv"); $csvPick = $this->dialog->ask($this->output, PHP_EOL . '</fg=yellow>Please Enter The Name Of The CSV You Want To Process (branch.csv) - ', 'branch.csv'); $userName = $this->dialog->ask($this->output, 'Please Enter The User Name To Upload Pics As (admin)', 'admin'); $user = $this->em->getRepository('SudouxCmsUserBundle:User')->loadUserByUsername($userName); if (file_exists($this->uploadPath . "/branches/" . $csvPick)) { $this->output->writeln(" File Found: " . PHP_EOL); $file = fopen($csvPick, "r"); // $this->output->writeln(implode(" - ",fgetcsv($file))); print_r(fgetcsv($file)); $picKey = $this->dialog->ask($this->output, 'Which Field(#) Do you want to key the pic off of (1)?', 1); while (($newBranchInfo = fgetcsv($file)) !== FALSE) { $x++; $globResults = glob("{$this->uploadPath}/branches/{$newBranchInfo[$picKey]}.*"); if ($globResults) { $ext = pathinfo($globResults[0], PATHINFO_EXTENSION); $this->output->writeln(PHP_EOL . implode(" - ", $newBranchInfo)); if (!$this->dialog->askConfirmation($this->output, PHP_EOL . "Are You Sure You Want To Add Pic( {$globResults['0']}) To This Branch?</question>? ", false)) { return; } $savePath = realpath($baseRoot) . "/web/uploads/sites/" . $this->site->getId() . "/public/"; $picName = "{$newBranchInfo[$picKey]}.{$ext}"; $uploadedPicPath = $globResults[0]; $MIMEtype = mime_content_type($uploadedPicPath); while (file_exists($savePath . $picName)) { $picName = $newBranchInfo[$picKey] . "_{$counter}." . $ext; $counter++; $this->output->writeln("File Name Exists - New Name: <fg=blue>{$picName}</fg=blue>"); } $openFileName = $zipPicRoot . $picName; rename($openFileName, $savePath . $picName); $photo = new File(); $size = filesize($savePath . $picName); $photo->setPath("uploads/sites/" . $this->site->getId() . "/public/" . $picName); $photo->setFilesize($size); $photo->setName($newBranchInfo[0]); $photo->setUser($user); $photo->setMimeType($MIMEtype); $photo->setSite($this->site); $this->em->persist($photo); try { $updateBranch = $this->em->getRepository('SudouxMortgageBundle:Branch')->findOneBySiteAndNmlsId($this->site, $newBranchInfo[1]); if (isset($updateBranch)) { $this->output->writeln("Branch Exists - Updating Now"); $updateBranch->setBranchPhoto($photo); $this->em->persist($updateBranch); } else { $this->output->writeln("Branch Does Not Exist - Not Updating"); } } catch (NonUniqueResultException $e) { $this->output->writeln("More Than One Branch By This NMLS Number Exists - Not Updating"); } $this->em->flush(); } } fclose($file); } }