forked from vmelnik-ukraine/DoctrineEncryptBundle
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
571afbd
commit 14850a2
Showing
1 changed file
with
13 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,10 +12,10 @@ | |
use Symfony\Component\Console\Question\ConfirmationQuestion; | ||
|
||
/** | ||
* Hello World command for demo purposes. | ||
* | ||
* Batch encryption for the database | ||
* | ||
* @author Marcel van Nuil <[email protected]> | ||
* @author Michael Feinbier <[email protected]> | ||
*/ | ||
class DoctrineEncryptDatabaseCommand extends ContainerAwareCommand | ||
{ | ||
|
@@ -27,8 +27,8 @@ protected function configure() | |
{ | ||
$this | ||
->setName('doctrine:encrypt:database') | ||
->setDescription('Decrypt whole database on tables which are encrypted') | ||
->addArgument('encryptor', InputArgument::OPTIONAL, 'The encryptor u want to decrypt the database with') | ||
->setDescription('Encrypt whole database on tables which are not encrypted yet') | ||
->addArgument('encryptor', InputArgument::OPTIONAL, 'The encryptor you want to decrypt the database with') | ||
->addArgument('batchSize', InputArgument::OPTIONAL, 'The update/flush batch size', 20); | ||
|
||
} | ||
|
@@ -57,9 +57,9 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
{ | ||
$subscriber->setEncryptor($input->getArgument('encryptor')); | ||
} else { | ||
$output->writeln("\nGiven encryptor does not exists"); | ||
$output->writeln("Supported encryptors: " . implode(", ", array_keys($supportedExtensions))); | ||
$output->writeln("You can also define your own class. (example: Ambta\DoctrineEncryptBundle\Encryptors\Rijndael128Encryptor)"); | ||
$output->writeln('\nGiven encryptor does not exists'); | ||
$output->writeln('Supported encryptors: ' . implode(', ', array_keys($supportedExtensions))); | ||
$output->writeln('You can also define your own class. (example: Ambta\DoctrineEncryptBundle\Encryptors\Rijndael128Encryptor)'); | ||
return; | ||
} | ||
} | ||
|
@@ -81,20 +81,20 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
|
||
//Count propperties in metadata | ||
foreach($propertyArray as $property) { | ||
if($annotationReader->getPropertyAnnotation($property, "Ambta\DoctrineEncryptBundle\Configuration\Encrypted")) { | ||
if($annotationReader->getPropertyAnnotation($property, 'Ambta\DoctrineEncryptBundle\Configuration\Encrypted')) { | ||
$propertyCount++; | ||
} | ||
} | ||
} | ||
|
||
$confirmationQuestion = new ConfirmationQuestion("<question>\n" . count($metaDataArray) . " entitys found which are containing " . $propertyCount . " properties with the encryption tag. \n\nWhich are going to be encrypted with [" . $subscriber->getEncryptor() . "]. \n\nWrong settings can mess up your data and it will be unrecoverable. \nI advise you to make <bg=yellow;options=bold>a backup</bg=yellow;options=bold>. \n\nContinu with this action? (y/yes)</question>", false); | ||
$confirmationQuestion = new ConfirmationQuestion("<question>\n" . count($metaDataArray) . " entities found which are containing " . $propertyCount . " properties with the encryption tag. \n\nWhich are going to be encrypted with [" . $subscriber->getEncryptor() . "]. \n\nWrong settings can mess up your data and it will be unrecoverable. \nI advise you to make <bg=yellow;options=bold>a backup</bg=yellow;options=bold>. \n\nContinue with this action? (y/yes)</question>", false); | ||
|
||
if (!$question->ask($input, $output, $confirmationQuestion)) { | ||
return; | ||
} | ||
|
||
//Start decrypting database | ||
$output->writeln("\nEncrypting all fields this can take up to several minutes depending on the database size."); | ||
$output->writeln("\nEncrypting all fields can take up to several minutes depending on the database size."); | ||
|
||
//Loop through entity manager meta data | ||
foreach($metaDataArray as $metaData) { | ||
|
@@ -109,7 +109,7 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
|
||
//Count propperties in metadata | ||
foreach ($propertyArray as $property) { | ||
if ($annotationReader->getPropertyAnnotation($property, "Ambta\DoctrineEncryptBundle\Configuration\Encrypted")) { | ||
if ($annotationReader->getPropertyAnnotation($property, 'Ambta\DoctrineEncryptBundle\Configuration\Encrypted')) { | ||
$propertyCount++; | ||
} | ||
} | ||
|
@@ -120,7 +120,7 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
|
||
//If class is not an superclass | ||
$i = 0; | ||
if (!$annotationReader->getClassAnnotation($reflectionClass, "Doctrine\ORM\Mapping\MappedSuperclass")) { | ||
if (!$annotationReader->getClassAnnotation($reflectionClass, 'Doctrine\ORM\Mapping\MappedSuperclass')) { | ||
$iterator = $this->getEntityIterator($entityManager, $metaData->name); | ||
$totalCount = $this->getTableCount($entityManager, $metaData->name); | ||
|
||
|
@@ -144,7 +144,7 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
} | ||
|
||
//Say it is finished | ||
$output->writeln("\nEncryption finished values encrypted: " . $subscriber->encryptCounter . " values.\nAll values are now encrypted."); | ||
$output->writeln("\nEncryption finished. Values encrypted: <info>" . $subscriber->encryptCounter . " values</info>.\nAll values are now encrypted."); | ||
} | ||
|
||
/** | ||
|