Run plugin's shell in cakephp 2.0 - shell

I have created a new CakePHP 2.0 app and want to run a plugin's shell.
<?php
// app\Plugin\Tmaker\Vendors\Shells\TmakerShell.php
class TmakerShell extends Shell {
}
However, I can't see it when running Console/cake from the command-line.
Please advise my what I have missed?

According to the latest documentation, the path for shells has changed to app/Console/Command/.
Move your shell to the following location: app/Plugin/Tmaker/Console/Command/TmakerShell.php (not sure if plugin directory names are camel-cased in CakePHP 2.0, but it seems to work either way.)
<?php
class TmakerShell extends Shell {
public function main() {
$this->out('It works!');
}
}
As CakePHP 2.0 requires you to load plugins manually, you also need to update app/Config/bootstrap.php by adding CakePlugin::loadAll(); or CakePlugin::load('Tmaker'); to the last line.
You should then be able to access your shell from the command-line. It looks like this in Windows:
C:\xampplite\htdocs\cake2\app>..\lib\Cake\Console\cake Tmaker.tmaker
Welcome to CakePHP v2.0.0-beta Console
---------------------------------------------------------------
App : app
Path: C:\xampplite\htdocs\cake2\app\
---------------------------------------------------------------
It works!

Related

Grails test-app updating function being tested and test print out problems

I am running grails 2.3.3 in a GGTS.
I am successfully running a single unit test for a service function within the Spring GGTS.
I am hoping to be able to use this unit test to develop the particular function - such an approach will really speed up my development going forward.
This means I need to make changes to the service function that is being tested and then retest over and over again (no doubt a sad reflection on my coding skills!). The problem is when I make a change to the logic or any log.debug output it does not come through in the test. In other words the test continues to run against the original service function and not the updated one.
In order for me to force it to use the updated function the only way I have found that will do this is to restart the GGTS!
Is there a command I can use in GGTS to force a test on the most recent version of the function I am testing?
Here are the commands I am using within the GTTS:
test-app unit: UtilsService
I do run a clean after a function update without any success:
test-app -clean
I am also struggling with getting additional output from within the test function - introducing 'println' or 'log.debug' commands results in a failure of the test.
It would be useful to know of a good link to documentation about the test syntax - I have looked at grails section 12 about testing in general.
Here is the test file:
package homevu1
import grails.test.mixin.TestFor
import spock.lang.Specification
/**
* See the API for {#link grails.test.mixin.services.ServiceUnitTestMixin} for usage instructions
*/
#TestFor(UtilsService)
class UtilsServiceSpec extends Specification {
// to test utilSumTimes for example use the command :
// test-app utilSumTimes
// test-app HotelStay
def setup() {
}
def cleanup() {
}
void "test something"() {
when:
def currSec = service.utilSumTimeSecs( 27, 1, false)
//println "currSec" , currSec
then:
//println "currSec" , currSec
assert currSec == "26"
}
}
If I uncomment either of the println lines these comments are not displayed and the test fails.
Welcome any suggestions.
-mike
I've to get this working now by running grail from a command prompt (in MS Windows).
In the command prompt I moved to the root folder/directory of the grails project - in my case:
cd C:\grails\workspace\rel_3.1.0\HomeVu
Then I type grails to start a grails command line session.
The unit test command I used being:
test-app -unit UtilsService -echoOut -echoErr
That said I still am unable to successfully put any print commands in the test file - but I can use the assert to determine any problems.
Also output from the last log.debug line of the grails code of the service function fails to appears. Perhaps there is some output buffering issue with MS Windows here.
At least I can now do some rapid function development, by making changes to the service/function code and instantly test is against a set of known requirement conditions.
Hope this helps others.
-mike

CakePhp 2.4 "Error: Shell class HelloShell could not be found." Paths mess?

I have found several answers on that topic, but none did help me.
So here is the situation. I work on a ubuntu system and my default cakephp 2.4.4 installation is under:
/var/www/myproject/
/gkm-be (this is my app)
/lib/Cake
So all paths here are default and the gkm_be app in general is working smoothly.
In my .bashrc I have the following setting:
PATH=$PATH:$HOME/bin
export PATH="$PATH:/var/www/myproject/lib/Cake/Console/"
When I open a new shell and go to the directory /var/www/myproject/gkm-be and type
Console/cake
I get the error
bash: Console/cake: File or directory not found
after
cd /var/www/myproject/gkm-be/Console/
if I enter cake then I get the core cake with following output
Welcome to CakePHP v2.4.4 Console
---------------------------------------------------------------
App : Console
Path: /var/www/myproject/gkm-be/Console/
---------------------------------------------------------------
Current Paths:
-app: Console
-working: /var/www/myproject/gkm-be/Console
-root: /var/www/myproject/gkm-be
-core: /var/www/myproject/lib
Changing Paths:
Your working path should be the same as your application path. To change your path use the '-app' param.
Example: -app relative/path/to/myapp or -app /absolute/path/to/myapp
Available Shells:
[CORE] acl, api, bake, command_list, console, i18n, schema, server, test, testsuite, upgrade
Note the paths for -app and -working
Not to mention of course that my HelloShell located under
/var/www/myproject/gkm-be/Console/Command/HelloShell.php
is neither listed nor can be called.
Were did I set a path wrong? Can anybody spot the mistake?
Calamity Jane
PS: The code from the shell:
class HelloShell extends AppShell
{
public function main()
{
date_default_timezone_set('Europe/Berlin');
$this->out('Hello world.');
}
}
go to /var/www/myproject/gkm-be and run the command
../lib/Cake/Console/cake Hello

Update CodeIgniter from version 1.7.2 to 2.0.0 - class CI_Controller not found

I'm trying to update my project from CI version 1.7.2 to CI v. 2.0.0 (then I will update to next versions - but first I need to deal with that).
So:
Path to my CI is:
/home/user/www/mysite. That’s all right, it’s written here: http://codeigniter.com/user_guide/installation/upgrade_200.html That I should replace my system folder (except application folder) with this from v2.0.
I copied these directories from 2.0.0’s system folder (that’s core, database, fonts, helpers, language, libraries) and replaced older ones. I’ve done all other things - and after trying to launch my new version of CI - it shows
Fatal error: Class ‘CI_Controller’ not found in/home/user/sitesystem/application/controllers/test.php on line 3.
MY /system/core folder contains file Controller.php and it starts with
class CI_Controller
- so everything should work fine - what’s going on?
First, in CI 2, the application folder is in the root dir, not under the system directory. And second, if you watch closely your error say:
/home/user/sitesystem/application/
and you wrote previously, that the path is:
/home/user/www/mysite
so i would check this 2 things first.

DocBlox CodeIgniter No direct script access

I've just installed DocBlox on Windows running Apache.
In a CodeIgniter application I have removed the following line from the top of my script
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
But when I run
docblox -f main.php -t docs
I get the error message
No direct script access allowed
Does anyone know what else is stopping this from working?
Thanks
Short version
You probably have a class that is not in the source that DocBlox parses but is in your include_path. Try to find which file causes this error using the verbose (-v) option and check which classes are not in your project's source but are being invoked.
Explanation
DocBlox does not load files using Reflection and should thus not execute the given code unless a class could not be found in the project files but could be found using the include_path.
For example:
class A extends B
{
}
if class B is not parsed by DocBlox then DocBlox will try to find it in your include path so that information can be gathered on it. In this case A is not executed but B is.

Changing cache_dir and log_dir with Symfony2

Because of deployment constraints, I would like to have the log and cache directories used by my Symfony2 application somewhere under /var/... in my file system. For this reason, I am looking for a way to configure Symfony and to override the default location for these two directories.
I have seen the kernel.cache_dir and kernel.log_dir and read the class Kernel.php. From what I have seen, I don't think that it is possible to change the dir locations by configuration and I would have to patch the Kernel.php class.
Is that true, or is there a way to achieve what I want without modifying the framework code?
Add the following methods to app/AppKernel.php (AppKernel extends Kernel) making them return your preferred paths:
public function getCacheDir()
{
return $this->rootDir . '/my_cache/' . $this->environment;
}
public function getLogDir()
{
return $this->rootDir . '/my_logs';
}
I was happy to find your post, but I was a little bit confused of the unhelping answers.
I got the same problem and found out that the logs are depending on the config parameter
kernel.logs_dir.
So I just added it to my config.yml parameters:
kernel.logs_dir: /var/log/symfonyLogs
I hope it will helpfull for you even, if its a late answer.
i think the easiest way is to link the folder to another place. We have made this on the prod server but when you develop local perhaps on windows its a bit complicated to set the symlinks.
ln -s /var/cache/ /var/www/project/app/cache
something like this.
I would like to offer an alternative and that is to set environment variables to change these directories. This way it's easier to set depending on the stage. (testing, production or development)
export SYMFONY__KERNEL__CACHE_DIR "/your/directory/cache"
export SYMFONY__KERNEL__LOGS_DIR "/your/directory/logs"
Environment variables can also be set in the virtual host with SetEnv.
When reading kernel parameters symfony will look for all the $_SERVER variables that start with SYMFONY__, strip the first part and convert all the double underscores into a .
Source code
See line 568 to 608
In symfony you can override the cache (and logs) directory by extending the method in AppKernel.
// app/appKernel.php
class AppKernel extends Kernel
{
// ...
public function getCacheDir()
{
return $this->rootDir.'/'.$this->environment.'/cache';
}
}
Check out http://symfony.com/doc/current/cookbook/configuration/override_dir_structure.html#override-cache-dir
I used the configuration solution from Dragnic but I put the paths in the parameters.yml file because this file is ignored by git. in other words, it's not synchronized from my PC to the git repository so there is no impact in the prod environment.
# app/config/parameters.yml
parameters:
database_driver: pdo_mysql
[...]
kernel.cache_dir: "T:/project/cache"
kernel.logs_dir: "T:/project/logs"
Configuration: Windows7, WAMP 2.4 and Symfony 2.3.20.
But you have to know that:
Overwriting the kernel.cache_dir parameter from your config file is a very bad idea, and not a supported way to change the cache folder in Symfony.
It breaks things because you would now have different cache folders for the kernel Kernel::getCacheDir() and for the parameter.
Source: https://github.com/symfony/AsseticBundle/issues/370
So you should use it only in dev environment and if you don't want to change the content of the app/AppKernel.php file, otherwise see the other answers.
No accepted answer, and a really old question, but I found it with google, so I post here a more recent way to change the cache directory, and the logs directory, (source here)
remember, short syntax for arrays require php 5.4
you can select the env to modify, and manage different cache and logs directories if you want
public function getCacheDir()
{
if (in_array($this->environment, ['prod', 'test'])) {
return '/tmp/cache/' . $this->environment;
}
return parent::getCacheDir();
}
public function getLogDir()
{
if (in_array($this->environment, ['prod', 'test'])) {
return '/var/log/symfony/logs';
}
return parent::getLogDir();
}

Resources