Search code examples
cakephpcakephp-2.5

Use schema in shell


In a plugin context, I'm writing a shell subcommand and I need to call a public method of the schema:

// app\Plugin\FooManager\Config\Schema\schema.php
App::uses('BaseSchema', 'FooManager.Config/Schema');
class FooManagerSchema extends BaseSchema {
    public function getLocalisableValues() {
    }
}

As usual, I can't figure out the syntax.

// app\Plugin\FooManager\Console\Command\DevShell.php
class DevShell extends AppShell {
    public function i18n_dump_database_values() {
        $schema = ????????;
        $schema->getLocalisableValues();
    }
}

How can I load an instance of FooManagerSchema into $schema?


Solution

  • Shameful cakeless workaround to make it work at any cost (please don't try this at home, kittens can be hurt):

    // app\Plugin\FooManager\Console\Command\DevShell.php
    class DevShell extends AppShell {
        public function i18n_dump_database_values() {
            // Ugly (and will possibly break things):
            include_once(__DIR__ . '/../../../../../lib/Cake/Model/CakeSchema.php');
            include_once(__DIR__ . '/../../Config/Schema/schema.php');
            $schema = new FooManagerSchema();
    
            $schema->getLocalisableValues();
        }
    }