Hibernate-core 5.10.2 and Hibernate-envers-5.10.2 with persistance.xml
if i add hibernate.envers.autoRegisterListeners to be true I got:
org.hibernate.event.service.spi.EventListenerRegistrationException: Duplicate event listener found
at org.hibernate.event.service.internal.EventListenerGroupImpl.listenerShouldGetAdded(EventListenerGroupImpl.java:126)
at org.hibernate.event.service.internal.EventListenerGroupImpl.appendListener(EventListenerGroupImpl.java:91)
at org.hibernate.event.service.internal.EventListenerGroupImpl.appendListeners(EventListenerGroupImpl.java:85)
at org.hibernate.event.service.internal.EventListenerRegistryImpl.appendListeners(EventListenerRegistryImpl.java:156)
at org.hibernate.envers.boot.internal.EnversIntegrator.integrate(EnversIntegrator.java:86)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:278)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:452)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:889)
If I set flag to be false, above exception does not appears but No insertion Query fired for _AUD tables.
I am using Karaf 4.0.7 with feature installed as:
<feature version="5.2.10.Final" >hibernate-orm</feature>
<feature version="5.2.10.Final" >hibernate-envers</feature>
Can anyone help me out what I am Missing??
Issue Resolved. Listeners needs to be register , SO i added :
EventListenerRegistry listenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );
listenerRegistry.appendListeners( EventType.POST_UPDATE, new EnversPostUpdateEventListenerImpl( enversService ) );
listenerRegistry.appendListeners( EventType.POST_INSERT, new EnversPostInsertEventListenerImpl( enversService ) );
listenerRegistry.appendListeners( EventType.PRE_UPDATE, new EnversPreUpdateEventListenerImpl( enversService ) );
Related
I'm trying to post a comment to WordPress (4.7.0) using basic authentication as described in the documentation and in WP REST API: Setting Up and Using Basic Authentication.
However, I keep getting 401 errors back.
{"code":"rest_comment_login_required","message":"Sorry, you must be logged in to comment.","data":{"status":401}}
I activated the basic authentication plugin which then should turn this call into an authenticated call, right?
You need to add a filter to your theme's functions.php file:
add_filter( 'rest_allow_anonymous_comments', function ( $allow_anonymous, $request ) {
// ... custom logic here ...
return true; // or false to prohibit anonymous comments via post
}, 10, 2 );
Documentation: https://developer.wordpress.org/reference/hooks/rest_allow_anonymous_comments/
Go to your root WordPress folder like rootfolder/wp-includes/rest-api/endpoints
Open the file: class-wp-rest-comments-controller.php
Change the line:
$allow_anonymous = apply_filters( 'rest_allow_anonymous_comments', false , $request );
to
$allow_anonymous = apply_filters( 'rest_allow_anonymous_comments', true, $request );
That's all
I am not an expert in Symfony, I need to add a new console option --country=XX to the symfony console.
This isnt a command, its an option which changes how whatever command is run, executes by selecting a different database to operate on by building the doctrine.dbal.dbname parameter such as api_fr, api_de, api_es, etc.
I have tried to search for a way to do this, but unfortunately everything comes back to adding commands, which is not what I want to do, I want to add an option.
I am building an API which part of it works with Symfony 2.8 and another part is using Symfony 3.x. I suppose the answer might be the same in both versions, but if you know how to do this in both versions and they are separate, please let me know.
You can add an EventListener like this exemple:
use Symfony\Component\Console\Input\InputOption;
class YourOptionEventListener
{
public function onConsoleCommand(ConsoleCommandEvent $event)
{
$inputDefinition = $event->getCommand()->getApplication()->getDefinition();
// add the option to the application's input definition
$inputDefinition->addOption(
new InputOption('yourOption', null, InputOption::VALUE_OPTIONAL, 'Description of the option', null)
);
}
}
Then add it as a service:
<?xml version="1.0" ?>
<container ...>
<services>
<service id="app_yourOption.console_event_listener"
class="App\YourOptionBundle\EventListener\YourOptionEventListener">
<tag name="kernel.event_listener" event="console.command" method="onConsoleCommand" />
</service>
</services>
</container>
You can check this documentation, in "Add a global command option" chapter, you can find what you need:
http://php-and-symfony.matthiasnoback.nl/2013/11/symfony2-add-a-global-option-to-console-commands-and-generate-pid-file/
The best practice of 2018 and Symfony 3+ is to extend Symfony Application:
<?php
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputOption;
final class SomeApplication extends Application
{
protected function getDefaultInputDefinition()
{
$definition = parent::getDefaultInputDefinition();
$definition->addOption(new InputOption(
'country',
null,
InputOption::VALUE_REQUIRED,
'Country to use'
));
return $definition;
}
}
Then anywhere in your command or service with Symfony\Component\Console\Input\InputInterace service present, just call:
$country = $input->getOption('country');
Do you want to know more?
I've extended the answer in the 4 Ways to Add Global Option or Argument to Symfony Console Application post.
On a WordPress site, we tried updating the WooCommerce Subscriptions plugin. It got part way, but then went inactive with this message:
WooCommerce Subscriptions is inactive. This version of Subscriptions requires WooCommerce 2.3 or newer. Please update WooCommerce to version 2.3 or newer
We're running WooCommerce 2.5.3 ... so already newer than 2.3.
Putting in a ticket with WooCommerce yields this message:
It looks like your WooCommerce database needs updating! Run the Database Updater in your WordPress admin. You can still submit the ticket below.
In the Woocommerce area there is a System Status report area. It shows:
Database
WC Database Version:
woocommerce_sessions ✔
That's a blank by WC Database Version.
Where is the WC Database version stored? Can we update that? Or manually run the DB Updater?
Thanks!
If you want to manually trigger a WooCommerce data update from the CMS, you can use this url:
wp-admin/admin.php?page=wc-settings&do_update_woocommerce=1
I tried the answers in this thread including the URL trick, but as of August 2019 they didn't seem to work and force the Woo update.
I have found the best way to force a WooCommerce update is via WP CLI and running the following command:
wp wc update
OK, actually, between the IT manager and me, I think we figured this out.
woocommerce-subscriptions.php checks the woocommerce_db_version option near the top of the file.
if ( ! is_woocommerce_active() || version_compare( get_option( 'woocommerce_db_version' ), '2.3', '<' ) ) {
add_action( 'admin_notices', 'WC_Subscriptions::woocommerce_inactive_notice' );
return;
}
get_option is a means of checking the wp_options table.
https://codex.wordpress.org/Function_Reference/get_option
And the woocommerce_db_version option was missing. So ... an insert statement got it behaving!
insert into wp_options (option_name, option_value, autoload) Values ('woocommerce_db_version', '2.5.3', 'yes');
I had the same problem. I checked the MySQL wp_options table and the Woocommerce version is called woocommerce_version, not woocommerce_db_version. So I changed:
if ( ! is_woocommerce_active() || version_compare( get_option( 'woocommerce_db_version' ), '2.3', '<' ) ) {
add_action( 'admin_notices', 'WC_Subscriptions::woocommerce_inactive_notice' );
return;
}
to the following:
if ( ! is_woocommerce_active() || version_compare( get_option( 'woocommerce_version' ), '2.3', '<' ) ) {
add_action( 'admin_notices', 'WC_Subscriptions::woocommerce_inactive_notice' );
return;
}
This solved the problem for me.
...JohnDF
I'm drawing a blank. I have code working locally (which is MAMP). When moving to a nginx ubuntu box (running php-fpm), for some reason, phpactiverecord is acting up.
I finally traced it down to this - All of my model classes, I have to load manually. If I add a require_once() underneath my code, then it works fine. If I don't, then I get errors like:
PHP Fatal Error: Class not found ... on the models I've created..
Does anyone have ANY idea what direction I could troubleshoot this in? I checked permissions to the models folder (which is not in the public root), echo'd out the path that is sent over to cfg->set_model_directory is correct, etc..
This sound like a nginx or php thing? I'm guessing nginx since this works on my MAMP?
Doesn't work:
ActiveRecord\Config::initialize(
function ($cfg) {
$cfg->set_model_directory(BASE_PATH . '/models');
$cfg->set_connections(
array(
'development' => 'mysql://blah:removed#localhost/com_dbname'
)
);
}
);
Works:
ActiveRecord\Config::initialize(
function ($cfg) {
$cfg->set_model_directory(BASE_PATH . '/models');
$cfg->set_connections(
array(
'development' => 'mysql://blah:removed#localhost/com_dbname'
)
);
}
);
require_once(BASE_PATH . '/models/model1.php');
require_once(BASE_PATH . '/models/model2.php');
Update
Adding in actual code to help identify issue:
require_once ('../lib/php-activerecord/ActiveRecord.php');
ActiveRecord\Config::initialize(
function ($cfg) {
$cfg->set_model_directory('/var/www/uc1/models');
$cfg->set_connections(
array(
'development' => 'mysql://test_usr:test_pwd#localhost/test_db'
)
);
}
);
require_once ('/var/www/uc1/models/ucurls.php'); //Name of model file. Must manually include to get this to work on my nginx server.
$_record = UCUrls::find_by_urlkey('example.com/123');
echo "urlkey=" . $_record->urlkey;
I solved this issue in windows adding a line in the file ActiveRecord.php,
in the function activerecord_autoload($class_name)
at the line 39 or 40
$file = "$root/$class_name.php";
//add this line
$file = strtolower($file);
Set trace in ActiveRecord.php too look where are ActiveRecord is searching for models.
But I think your issue is in filesystem - Mac OS X by default uses Case Insensitive filesystem, while Ubuntu's Case Sensitive filesystem.
So your model UCUrls should be in file /var/www/uc1/models/UCUrls.php, not in /var/www/uc1/models/ucurls.php
I have attached an observer on kernel.exception to print a custom error page.
In prod, with debug mode : it's OK.
In prod, with no-debug mode : it's NOK.
I have try to clear cache (--env=prod --no-debug), (--env=prod), (and delete directly files).
No result.
Like the kernel.exception event was disabled or stopped.
In container cache file (appProdProjectContainer.php) I see my observer entry :
$instance->addListenerService('kernel.exception', array(0 => 'ui.exception.event_listener', 1 => 'onKernelException'), 0);
[...]
$instance->addListenerService('kernel.exception', array(0 => 'twig.exception_listener', 1 => 'onKernelException'), -128);
Perhaps, it's a priority issue ? (-128 vs 0) ?
I have try to change it : No result.
Have you an idea, a way ?
Thanks.
In my case I have upgraded vendors for old symfony2 application and my app/AppKernel.php have such a code
\Monolog\ErrorHandler::register($logger);
After disabling that line my error listener start working.