Launching Doctrine 2 CLI Tools Tasks from a Script Launch from a Browser

A little background information: I'm working on integrating Doctrine into a CodeIgniter application. It works for me, but I would like to be able to run Doctrine command line tasks (CLI) from a browser, i.e. Not a command line script.

The reason I wish for this is because I will run Doctrine and CodeIgniter in a shared hosting package, where I will not have access to the command line.

This seems like a very basic feature, but not available in Doctrine 2.

My last aspiration will be to go to the command line tool and find out how the tasks are performed, and then duplicate this code in the CodeIgniter controller.

If there is an easier way to do this, please let me know.

Thank!

An unanswered duplicate posted some time ago.

+3
source share
2 answers

For the next

$doctrine = \Zend_Registry::get('doctrine');
$em = $doctrine->getEntityManager();
$tool = new \Doctrine\ORM\Tools\SchemaTool($em);

Get SQL to update the current schema:

$sqlArray = $tool->getUpdateSchemaSql($em->getMetadataFactory()->getAllMetadata());

Refresh Schema with Current Metadata

$res = $tool->updateSchema($em->getMetadataFactory()->getAllMetadata());

Create a diagram.

$res = $tool->createSchema($em->getMetadataFactory()->getAllMetadata());

This applies to the install script. Just create and check the db connection

$conn = $doctrine->getConnection();
$sql = "SELECT * FROM users";
try {
    $stmt = $conn->query($sql); // Simple (too simple?)
    die('Already installed');
} catch (Exception $e) {
    // Table not found, continue
}

Then create your circuit.

+1
source

You probably don't want to try to run command line tools without a command line.

However, you can do it yourself in the scripts quite simply. For example, if you want to do what orm: schema-tool: * does, you start here

0
source

All Articles