Closed alexandru-elisei closed 8 years ago
Firstly, init_target_location()
is actually a relic that is not currently used. And I am not quite sure about what we want. I see two basic use cases:
block_foo
into a directory /block/foo
(it must be /blocks/foo
). They should be able to simply specify the target Moodle location./tmp/just_testing
.The main cli/generate.php could support both scenarios via two alternative arguments:
--target-moodle
would allow to specify target Moodle's dirroot and the actual path within that Moodle would be determined by the component type.--target-dir
would allow to specify target directory explicitly.Normally just one of the two options would be provided. If both options would be provided leading to different locations, exception would be thrown. If no location would be provided, the script would assume --target-moodle
set to $CFG->dirroot
of its own Moodle instance.
So:
php generate.php --target-moodle
means that the files will be created in the default location within the moodle installation directory.php generate.php --target-dir=/test
means that the plugin files will be created at /test/pluginnamephp generate.php
is the same as the 1.php generate.php --target-dir=/test --target-moodle
throws an exceptionphp generate.php --target-dir=/path/to/moodle/root --target-moodle
is legal.Have I understood correctly?
php generate.php
will generate the plugin into the current Moodle (where the pluginskel is installed)php --target-moodle=/var/www/vhost/moodledev
will generate the plugin into a Moodle installed at the given location. For example, a skeleton of a new editor_foo
would be generated in a directory /var/www/vhost/moodledev/lib/editor/foo/
php --target-dir=/tmp
will generate the plugin into that directory, ignoring the relative path to the plugin type. Skeleton of a new editor_foo
would be generated in /tmp/foo/
Let us make it a bit simpler than I originally described: If both these params are specified, throw an error message and explain that only one of them is expected.
--target-moodle
should make no assumptions on whether or not the moodle is actually installed there. In fact, it is valid to call php --target-moodle=/tmp
in which case, the editor would be generated into /tmp/lib/editor/foo
even if no moodle is actually present in /tmp
.
Got it, I like it.
Last we discussed about this we agreed that we should allow the user to specify a target location for the generated files.
After looking at the manager::init_target_location() function it seems to me that you want the user to specify a target directory and in that target directory you are going to build the entire Moodle hierarchy for the plugin directory. For example, if $moodleroot = /home/david and the component is local_name then the target directory for the files will be /home/david/local/name/.
Is this what you want?
I propose that we create the function
public function write_files($moodleroot = null)
which will call init_target_location($moodleroot), then it will generate all the plugin files in the directory specified by $this->rootdir.