Yii - How to yiic.php migrate up domain.com - yii

In yiic.php I include config: domian.config and futher crate yii app with main.config in which i try to use variables such as $db_serv, $db_user and so on. But these variables are undefined, although domian.config contains all of these.

are you sure your domain.config is executed before you load main.config?
$config = dirname(__FILE__) . '/protected/config/main.php';
this line in index.php on a yii project only defined a path. It dosn't execute the config in a first time.
Hope this helps

Related

Phinx path with subfolders

i want to have a better overview on the phinx migration files. i want something like this
/db/migration/1.8.5/ID-2065/my_file_name_1234567890
So i can use
'migrations' => '%%PHINX_CONFIG_DIR%%/db/migrations/'. $_ENV['APP_VERSION'],
In the docs only is something like this
migrations: %%PHINX_CONFIG_DIR%%/module/*/{data,scripts}/migrations
But how can i use there maybe a param from the command line.
See you
If your using the default YAML based configuration you can try using Phinx ENV vars (PHINX_ prefix) and then use a %%PHINX_VARNAME%% replacement. Note: I haven't actually tried this before. Read more about them here: http://docs.phinx.org/en/latest/configuration.html#external-variables
Otherwise if your using a PHP-based configuration file you can definitely access the $_ENV superglobal as you have described. Just be sure to call your bootstrap/init scripts so your application version is injected.
Rob

Angular CLI routing - Doesn't work on (Apache-) Server

I'm currently learning Angular-CLI for a Project. I succeeded in creating a simple little project with some routing Objects. In dev mode with ng serve, everthing works just fine. I can call the localhost:port in the browser and it works with the routing.
.
After a successful ng build -prod and moving all the stuff from the dist directory into my Server Folder (Apache24/htdocs), I start my Server and the main Side (mywebside) just works fine, the routing however does not... (i.e. localhost/about), instead I get a standart Error-Page as shown below:
Hope I was able to describe clearly what I did and where my problems are. I didn't posted any Code because I think the problem has to be else where.
Thank you for your help!
Manuel
Versions:
angular CLI: Beta.8 (latest)
(apache): 2.4.20
OK figured it out (with help from PierreDuc!)
You have to do 2 things:
add a .htaccess file: (just like that no filename!) in the folder where your index.html File is saved, insert this code:
ErrorDocument 404 /index.html
Edit the httpd.conf:
(you find the File in the Apache24/conf/ directory) search for the line:
<Directory "c:/Apache24/htdocs"> [...] -> in my Version of apache it is in line 244
a few lines further (after a few comments) you should find this line:
AllowOverride none -> in my Version of apache it is in line 264
change this line to
AllowOverride ALL
Thats it, now your Angular-CLI Website should work in the production build with routing objects
hope it might be helpful to other Developpers!
Thanks to PierreDuc!
Manuel

Using prestashop app from script located outside prestashop folder

I would like to use the prestashop app from a php script (external_script.php) located outside prestashop folder but still on the same server.
I could do that with Magento using :
require_once external_folder/magento/app/Mage.php;
I've tried to include prestashop/config/config.inc.php and prestashop/init.php but it redirects external_script.php to prestashop index.php
Any help would be greatly appreciated.
STEF
Add the following 2 lines at the start of your PHP script and then you can use all the classes and functions of PrestaShop:
include(dirname(__FILE__).'/../../config/config.inc.php');
include(_PS_ROOT_DIR_.'/init.php');
Also, include the main class file whose functions you want to call in the external script, it must be some of your module's file. For example:
include_once(__PATH__TO__CLASS__FILE__.'/xyzmodule.php');
After adding the above codes to include required files you can simply create objects of the class file you want to call and use its code. For example:
$xObj = new Xyzmodule();
$xObj->callingXFunction();
Hope this helps.
Magento is a well structured Zend project and it's easy to bootstrap the app to use it outside HTTP front controller, PrestaShop is another story it's really a big mess of spaghetti code, to bootstrap the app really depends os PS version and in some cases on installed modules that changes core behaviour.
To start you can first include the config/config.inc.php file that is on PS root dir, this will init the PS classloader and a bunch of configuration defines, if you use another autoloader and a old version on PS (<1.6) you need to workaround it, this is a simple bootstrap code that allow make any PS call:
<?php
// Load PS config and autoloader
define ('PS_DIR', __DIR__ . '/../ps-wtf');
require_once PS_DIR .'/config/config.inc.php';
// I use this to load compoper dependencies
require_once __DIR__ . '/../vendor/autoload.php';
// Call old __autoload() if present, required for PrestaShop old versions
if (function_exists('__autoload')) {
spl_autoload_register(function ($className) {
__autoload($className);
});
}
// Init Shop context, required some operation will fail without it
// adust accordly to multistore PS >= 1.6
Shop::setContext(Shop::CONTEXT_ALL);
// Init PS context, some modules require that this context was initialized and with correct data
// some core function fired in the admin require at least a employee
define ('PS_DEFAULT_EMPLOYEE', 1);
$psContext = Context::getContext();
if (!$psContext->employee) {
$psContext->employee = new Employee(PS_DEFAULT_EMPLOYEE);
}
// You can make any API call
$cat = new Category();
$cat->name = [
1 => 'New',
2 => 'Nuevo',
];
$cat->id_parent = 1;
$cat->save();
echo $cat->id;
Some PS functionality depends on correct initialization of some core classes (Yes it's crazy), you can take a look at ControllerCore and FrontControllerCore to see what is happening in the normal PS request flow.
I hope that this can help.
The way prestashop is designed won't let you do this kind of thing easily.
I think your best bet is to use their web service API : http://doc.prestashop.com/display/PS16/Using+the+PrestaShop+Web+Service
There is a PHP client library for this : https://github.com/PrestaShop/PrestaShop-webservice-lib/blob/master/PSWebServiceLibrary.php
You can also use curl, but be warned : they use a lot of different tokens on differents pages, this is quite annoying.
Here is some bash code to log yourself in, grab some tokens and upload an import file. You can adapt it to PHP curl and do anything else you want :
r=$(curl -k -c cookies -b cookies -s --request POST -d "ajax=1&token=&controller=AdminLogin&submitLogin=1&passwd=[YOU_PASSWORD_URL_ENCODED]&email=[YOUR_EMAIl_URL_ENCODED]" 'https://[YOUR_PRESTASHOP_HOST_OR_LOCALHOST]/[YOUR_PRESTASHOP_ADMIN_DIR]/index.php')
token=$(echo $r | sed -n 's/.*token=\([0-9a-zA-Z]*\).*/\1/gp')
admin_token=$(curl -k -c cookies -b cookies 'https://[YOUR_PRESTASHOP_HOST_OR_LOCALHOST]/[YOUR_PRESTASHOP_ADMIN_DIR]/index.php?controller=AdminDashboard&token='"$token" | sed -n '0,/.*?_token=\([-_0-9a-zA-Z]*\).*/s/.*?_token=\([-_0-9a-zA-Z]*\).*/\1/p')
brand_file_name=$(curl -k -c cookies -b cookies -F 'file=#local_path_of_a_file.xlsx' 'https://[YOUR_PRESTASHOP_HOST_OR_LOCALHOST]/[YOUR_PRESTASHOP_ADMIN_DIR]/index.php/configure/advanced/import/file/upload?_token='"$admin_token" | sed -nE 's/.*"name":"([^"]*).*/\1/gp')

How do you run a Yii command from within your Module?

Is it possible to have my module's custom commands show up in the list of application commands when you run yiic?
cd {yii_protected_folder}
yiic shell {full_path_to_my_yii_protected_folder}/config/console.php
I've tried adding the command into the commandMap array in console.php, but the command never shows up as an option in yiic.
'commandMap'=>array(
'passwordtest'=>array(
'class'=>'application.modules.myModule.commands.shell.passwordtestCommand',
),
The only way I can make it show up in yiic is to copy the passwordtestCommand.php file to {yii_protected_folder}/commands/shell/, but I'd rather keep the file within my module and reference it somehow.
It's actually not that hard, the CConsoleApplication-class has a getter for the CConsoleCommandRunner. This in its turn has an "addCommands()"-function that allows you to add paths. Just open up your protected/yiic.php and change it by this:
<?php
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
defined('YII_DEBUG') or define('YII_DEBUG',true);
require_once(dirname(__FILE__).'/../yii/yii.php');
$app = Yii::createConsoleApplication(dirname(__FILE__).'/config/console.php');
$app->commandRunner->addCommands('extraCommandPath');
$app->commandRunner->addCommands('extraCommandPath2');
$app->run();
After that you no longer require the yiic.php from the framework.
That should do it.
'commandMap'=>array(
'passwordtest'=>array(
'class'=>'application.modules.myModule.commands.shell.passwordtestCommand',
),
this help me with run module command in Yii 1.x
just add it into config/console.php or your different console config file.
also change the path part ".myModule.commands.shell.passwordtestCommand"
cheer, it's working for me.

loading sqlsrv driver in php.ini

i got php5.4.4
and i've downloaded sqlsrv driver for working with microsoft SQL
putted the dll in the ext folder of php and in the php.ini
;;;;;;;;;;;;;;;;;;;;;;;;
; Microsoft SQL Server ;
;;;;;;;;;;;;;;;;;;;;;;;;
extension=php_sqlsrv_54_nts.dll
sqlsrv.LogSubsystems=-1
sqlsrv.LogSeverity=-1
sqlsev.WarningsReturnAsErrors=0
but when loading
phpinfo()
the extension doesn't show up .
am i doing something wrong here?!
thanks in advance.
extension=php_sqlsrv_54_nts.dll should be in [ExtensionList] section, the rest of the parameters should be in [sqlsrv]:
(...)
[ExtensionList]
(...)
extension=php_sqlsrv_54_nts.dll
(...)
[sqlsrv]
sqlsrv.LogSubsystems=-1
sqlsrv.LogSeverity=-1
sqlsev.WarningsReturnAsErrors=0
(...)
You only need to set extension to the filename without extension these days (php 8.1):
extension=php_sqlsrv
The other 3 values are only needed if you don't want the defaults.
Most important is the extension_dir setting. It is recommended to use absolute path:
extension_dir = "C:\Program Files\php\ext"