New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added some basic CLI #49
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Command line interface (CLI) | ||
|
||
You will need to edit a Doctrine file for this to work. | ||
Goto | ||
Doctrine/ORM/Tools/Console/ConsoleRunner.php | ||
|
||
Add this | ||
|
||
// Fixtures | ||
new \Doctrine\Common\DataFixtures\Command\Add(), | ||
|
||
after | ||
|
||
new \Doctrine\ORM\Tools\Console\Command\InfoCommand(), | ||
|
||
Now you can use | ||
|
||
./doctrine fixtures:add | ||
|
||
## Options to fixtures:add | ||
|
||
--directory (-d) Directory with your fixtures - Its relative to your Entities\Proxies path *REQUIRED* | ||
--append (-a) If you want to append your fixtures instead | ||
--dump-fixtures Vieweing the fixtures instead of importing them | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
/* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the LGPL. For more information, see | ||
* <http://www.doctrine-project.org>. | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please remove this and add the license header instead |
||
|
||
namespace Doctrine\Common\DataFixtures\Command; | ||
|
||
use Symfony\Component\Console\Input\InputArgument, | ||
Symfony\Component\Console\Input\InputOption, | ||
Symfony\Component\Console, | ||
Doctrine\Common\DataFixtures\Loader, | ||
Doctrine\Common\DataFixtures\Executor\ORMExecutor, | ||
Doctrine\Common\DataFixtures\Purger\ORMPurger; | ||
|
||
class Add extends Console\Command\Command | ||
{ | ||
|
||
protected function configure() | ||
{ | ||
$this | ||
->setName('fixtures:add') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to be consistent with the naming used in the symfony2 bundle, it should be |
||
->setDescription('Adding fixtures to your database') | ||
->setDefinition(array( | ||
new InputOption( | ||
'directory', 'd', InputOption::VALUE_REQUIRED, | ||
'Directory with your fixtures - Its relative to your Entities\Proxies path' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why relative to the proxy path ? Fixtures have nothing to do with proxies |
||
), | ||
new InputOption( | ||
'append', 'a', InputOption::VALUE_NONE, | ||
'If you want to append your fixtures instead' | ||
), | ||
new InputOption( | ||
'dump-fixtures', null, InputOption::VALUE_NONE, | ||
'Viewing the fixtures instead of importing them' | ||
), | ||
)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the help of the command should be added too |
||
} | ||
|
||
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output) | ||
{ | ||
/** | ||
* @todo find a better way to get the path? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. which path ? you are getting the entity manager, not a path |
||
*/ | ||
$em = $this->getHelper('em')->getEntityManager(); /** @var $em \Doctrine\ORM\EntityManager */ | ||
|
||
if (!($input->getOption('directory'))) { | ||
$output->write($this->getSynopsis() . PHP_EOL); | ||
throw new \InvalidArgumentException('You need to input the directory'); | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need to use and if it is mandatory, it should be an argument, not an option. |
||
$dir = realpath($em->getConfiguration()->getProxyDir() . '/' . $input->getOption('directory') . '/'); | ||
if (! is_dir($dir)) { | ||
throw new \InvalidArgumentException(sprintf('The inputted "%s" is not a directory', $dir)); | ||
} else { | ||
$loader = new Loader(); | ||
$loader->loadFromDirectory($dir); | ||
$fixtures = $loader->getFixtures(); | ||
|
||
if ($input->getOption('append') === true) { | ||
$purger = new ORMPurger(); | ||
$executor = new ORMExecutor($em, $purger); | ||
$executor->execute($loader->getFixtures(), TRUE); | ||
} else { | ||
$purger = new ORMPurger(); | ||
$executor = new ORMExecutor($em, $purger); | ||
$executor->execute($loader->getFixtures()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why duplication the same logic when all you need to have as difference is using |
||
} | ||
|
||
} | ||
} | ||
} | ||
|
||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong. The library is using the MIT license.