I wrote a module to generate sitemap xml files. I want to generate them in a console route via cronjob, but the problem is that I get an exception Route with name "xy" not found when I iterate through the navigation container. The route definitely exists. If I call it in a web request, everything works fine. The stack trace looks like the following:
======================================================================
The application has thrown an exception!
======================================================================
Zend\Mvc\Router\Exception\RuntimeException
Route with name "home" not found
----------------------------------------------------------------------
vendor/zendframework/zend-mvc/src/Router/SimpleRouteStack.php:328
#0 vendor/zendframework/zend-navigation/src/Page/Mvc.php(260): Zend\Mvc\Router\SimpleRouteStack->assemble(Array, Array)
#1 vendor/zendframework/zend-navigation/src/Page/AbstractPage.php(999): Zend\Navigation\Page\Mvc->getHref()
#2 vendor/zendframework/zend-navigation/src/Page/AbstractPage.php(1035): Zend\Navigation\Page\AbstractPage->get('href')
#3 module/Sitemap/src/Sitemap/Service/GeneratorService.php(83): Zend\Navigation\Page\AbstractPage->__get('href')
#4 module/Sitemap/src/Sitemap/Controller/Cli/GeneratorController.php(31): Sitemap\Service\GeneratorService->generateSitemaps()
#5 vendor/zendframework/zend-mvc/src/Controller/AbstractActionController.php(82): Sitemap\Controller\Cli\GeneratorController->indexAction()
#6 [internal function]: Zend\Mvc\Controller\AbstractActionController->onDispatch(Object(Zend\Mvc\MvcEvent))
#7 vendor/zendframework/zend-eventmanager/src/EventManager.php(490): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#8 vendor/zendframework/zend-eventmanager/src/EventManager.php(214): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#9 vendor/zendframework/zend-mvc/src/Controller/AbstractController.php(118): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#10 vendor/zendframework/zend-mvc/src/DispatchListener.php(93): Zend\Mvc\Controller\AbstractController->dispatch(Object(Zend\Console\Request), Object(Zend\Console\Response))
#11 [internal function]: Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent))
#12 vendor/zendframework/zend-eventmanager/src/EventManager.php(490): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#13 vendor/zendframework/zend-eventmanager/src/EventManager.php(214): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#14 vendor/zendframework/zend-mvc/src/Application.php(314): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#15 public/index.php(15): Zend\Mvc\Application->run()
#16 {main}
======================================================================
You're using the CLI to process or generate your sitemap XML and thus using another Router, the CLI one.
So you need to fetch the other Router class -> HTTP Router.
array(
// HttpRouter
'router' => array(
'routes' => array(
// HTTP routes are here
)
),
// Console Router
'console' => array(
'router' => array(
'routes' => array(
// Console routes go here
)
)
),
)
So in order to get the HttpRouter:
$serviceManager->get('HttpRouter')
So if you want to use the HttpRouter you can do the following within your CLI Controller(s):
$cliRouter = $this->getEvent()->getRouter();
$this->getEvent()->setRouter($httpRouter);
// Http Routers can be called with the plugins
$this->url()->fromRoute('home');
// Use CLI router again
$this->getEvent()->setRouter($cliRouter);
Calling $this->url()->fromRoute('home'); this will throw your error in your question when using the CLI router. The "home" is not defined within your console routing and thus can not be found. Change your router to Http as you defined it in your HTTP routing.
Related
Fatal error: Uncaught Error: Call to a member function get_status() on null
I have WooCommerce and WooCommerce Subscriptions installed as well as YITH WooCommerce Customize My Account Page. And when I click on View Subscription, I get an error about the website having issues. When I show console in Chrome, and/or enable Debug, I get the following error message. Any help is greatly appreciated!
Fatal error: Uncaught Error: Call to a member function get_status() on null in /www/wp-content/plugins/woocommerce-subscriptions/templates/myaccount/subscription-details.php:18 Stack trace: #0 /www/wp-content/plugins/woocommerce/includes/wc-core-functions.php(249): include() #1 /www/wp-content/plugins/woocommerce-subscriptions/includes/class-wcs-template-loader.php(41): wc_get_template('myaccount/subsc...', Array, '', '/www/wp-content...') #2 /wordpress/wp-includes/class-wp-hook.php(286): WCS_Template_Loader::get_subscription_details_template(NULL) #3 /wordpress/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters('', Array) #4 /wordpress/wp-includes/plugin.php(465): WP_Hook->do_action(Array) #5 /www/wp-content/plugins/woocommerce-subscriptions/templates/myaccount/view-subscription.php(23): do_action('woocommerce_sub...', NULL) #6 /www/wp-content/plugins/woocommerce/includes/wc-core-functions.php(249): include('/www/wp-content...') #7 /www/wp-content/plugins/yith-woocommerce-customize-myaccount-page/includes/functio in /www/wp-content/plugins/woocommerce-subscriptions/templates/myaccount/subscription-details.php on line 18
Add this in your view-subscription.php file:
$subscription = wcs_get_subscription(basename($_SERVER['REQUEST_URI']));
You can find it in inside the folder woocommerce/myaccount of your theme. If you don't have it then you will have to create it by copying it from your woocommerce installation (check this link if you are not sure how it works).
That line should go just after the security check:
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
I am trying to execute a function when WooCommerce subscriptions creates a new subscription renewal order.
The reason being I wish to trap this event and pass details to a different database so we can trigger business workflows with our payment gateway, within our backend systems.
I've tried add_action and add_filter using wcs_renewal_order_created and then tested this by manually creating a renewal payment from the parent subscription order.
The hook calls the function, executes the code, puts some data into some test tables and then Wordpress shows an error as shown below.
Is there a simpler way to trigger a function when a renewal subscription order is created and if not, can anyone help as to why it seems to be failing calling a class that seems to set the payment method.
function log_renewal_order_interface($order, $subscription) {
write_log('woocommerce_subscriptions_renewal_order_created function called');
global $conn;
global $wpdb, $table_prefix;
write_log('woocommerce_subscriptions_renewal_order_created setting up test variables');
write_log($order);
$test1 = 'logged renewal order';
$test2 = 'order_id'.$order_id;
$test3 = 'not set';
$test4 = 'not set';
$test5 = 'not set';
// test table entry
$conn->insert('test_tabel',
array('test1' => $test1, 'test2' => $test2, 'test3' => $test3, 'test4' => $test4, 'test5' => $test5),
array('%s', '%s', '%s', '%s', '%s'));
}
add_filter ('wcs_renewal_order_created', 'log_renewal_order_interface', 10,2);
I then get the following error:
Fatal error: Uncaught Error: Call to a member function
set_payment_method() on null in
/home/ourislan/lifestyle5d.ourislandsvoice.com/wp-content/plugins/woocommerce-subscriptions/includes/admin/class-wcs-admin-meta-boxes.php:176
Stack trace: #0
/home/ourislan/lifestyle5d.ourislandsvoice.com/wp-includes/class-wp-hook.php(286):
WCS_Admin_Meta_Boxes::create_pending_renewal_action_request(Object(WC_Subscription)) #1 /home/ourislan/lifestyle5d.ourislandsvoice.com/wp-includes/class-wp-hook.php(310):
WP_Hook->apply_filters('', Array) #2
/home/ourislan/lifestyle5d.ourislandsvoice.com/wp-includes/plugin.php(453):
WP_Hook->do_action(Array) #3
/home/ourislan/lifestyle5d.ourislandsvoice.com/wp-content/plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-order-actions.php(131):
do_action('woocommerce_ord...', Object(WC_Subscription)) #4
/home/ourislan/lifestyle5d.ourislandsvoice.com/wp-includes/class-wp-hook.php(286):
WC_Meta_Box_Order_Actions::save(812, Object(WP_Post)) #5
/home/ourislan/lifestyle5d.ourislandsvoice.com/wp- in
/home/ourislan/lifestyle5d.ourislandsvoice.com/wp-content/plugins/woocommerce-subscriptions/includes/admin/class-wcs-admin-meta-boxes.php
on line 176
Figured it out. I needed to explicitly return $object at the end of the function.
I am trying to run a background script fired on a user action using wp_schedule_single_event, and although I have confirmed that the event is being scheduled and that wp_cron recognizes that the scheduled time has passed, it will not fire the event handler. To further complicate things, the code runs fine on my local WP install, but does nothing on my server.
To schedule the event, I am using:
if ( ! wp_next_scheduled( 'my_action_name' ) ) {
wp_schedule_single_event( time(), 'my_action_name' );
}
My handler action is defined as:
add_action('my_action_name', 'my_action_handler');
function my_action_handler () {
// do stuff
}
I have testing the wp core files and found that the following block (from wp-includes/cron.php:322) is where the script terminates:
var_dump('test1');
$cron_request = apply_filters( 'cron_request', array(
'url' => add_query_arg( 'doing_wp_cron', $doing_wp_cron, site_url( 'wp-cron.php' ) ),
'key' => $doing_wp_cron,
'args' => array(
'timeout' => 0.01,
'blocking' => false,
/** This filter is documented in wp-includes/class-wp-http-streams.php */
'sslverify' => apply_filters( 'https_local_ssl_verify', false )
)
), $doing_wp_cron );
var_dump('test2'); //exit here to test
wp_remote_post( $cron_request['url'], $cron_request['args'] );
On my local machine, the filter is applied, 'test2' is printed, and the script can continue to call wp_remote_post. On the server, however, the script terminates during the execution of apply_filter('cron_request'), printing 'test1' but not 'test2' and failing to reach wp_remost_post.
I have been unable to find the source for this filter to further debug. Wordpress.org says that the filter is defined within wp-includes/cron.php and that the one instance I have already cited is the only place it is ever applied, however, using Sublime multi-file search reveals that the string 'cron_request' appears only in the filter application I have cited.
I have read many post on wp_cron failing and have found no help other than non-descript 'Server configuration blocking wp_cron' answers. Any additional information on what type of server config or what else could be occuring here?
This action will trigger when someone visits your WordPress site, if the scheduled time has passed.
Maybe you can use
wp_schedule_event()
Instead of
wp_schedule_single_event()
I'm using wp_remote_post to post some info to a secure connection like this
$url = 'https://example.com/path/file.json';
wp_remote_post($url, array(
'sslverify' => false,
'timeout' => 60,
'body' => $body,
));
But I get an error:
SSL: CA certificate set, but certificate verification is disabled
I though sslverifyset to false should prevent that?
If I set sslverify => true it works but may cause problems on other servers
Here's the complete wp_error object:
WP_Error Object
(
[errors:WP_Error:private] => Array
(
[http_request_failed] => Array
(
[0] => SSL: CA certificate set, but certificate verification is disabled
)
)
[error_data:WP_Error:private] => Array
(
)
)
Maybe it's related but on Apache 2.2 it works while on Apache 2.4 it doesn't
Looks like your Apache 2.2 and 2.4 configurations are different. On 2.4 you probably have SSLVerifyClient set to required which would cause it to act like what you are describing. You'd need to set it to none:
http://httpd.apache.org/docs/current/mod/mod_ssl.html#SSLVerifyClient
I have follow the simple steps of zend documentation to develop a many simple console action.
My action have only one literal param. It works ok and the action is executed but before, in each call appears following notice and a stack trace.
How I do for remove / solve this message
Notice: Undefined index: HTTP_ACCEPT_LANGUAGE in C:\xampp\htdocs\pfc_desarrollo\module\SecureDraw\Module.php on line 124
Call Stack:
0.0003 121464 1. {main}() C:\xampp\htdocs\pfc_desarrollo\public\index.php:0
0.0079 237776 2. Zend\Mvc\Application::init() C:\xampp\htdocs\pfc_desarrollo\public\index.php:12
0.1589 1822568 3. Zend\Mvc\Application->bootstrap() C:\xampp\htdocs\pfc_desarrollo\vendor\zendframework\zendframework\library\Zend\Mvc\Application.php:239
0.2135 2232464 4. Zend\EventManager\EventManager->trigger() C:\xampp\htdocs\pfc_desarrollo\vendor\zendframework\zendframework\library\Zend\Mvc\Application.php:142
0.2135 2232584 5. Zend\EventManager\EventManager->triggerListeners() C:\xampp\htdocs\pfc_desarrollo\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php:204
0.2350 2387304 6. call_user_func() C:\xampp\htdocs\pfc_desarrollo\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php:460
0.2350 2387320 7. SecureDraw\Module->onBootstrap() C:\xampp\htdocs\pfc_desarrollo\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php:460
--------------------------------HELLOOOOOO------------------
This is my action / route definition
//module.php
'console' => array(
'router' => array(
'routes' => array(
'hello' => array(
'options' => array(
'route' => 'hello',
'defaults' => array(
'controller' => 'SecureDraw\Controller\Participant',
'action' => 'hello',
),
),
), //Line 124
),
),
),
//Participant.php
public function helloAction(){
return "--------------------------------HELLOOOOOO------------------";
}
You must be trying to access the Server Variable HTTP_ACCEPT_LANGUAGE inside your Module.php file.
$_SERVER['HTTP_ACCEPT_LANGUAGE'] is usally set using the Browser which has requested the page, but as your are running the app from the console it is probably not getting set.
You should check to see if it's set before accessing it.