multiple request getting fired cycle js - cyclejs

I am trying to write an application in cycle js using the cycle js http driver. Here's the response subscriptions for the call which is getting fired 3 times.
One subscription i need in the login page and another in the main. It's like:
login:
const response$ = http
.filter(res => res.request.url.indexOf("test/v3/users/login")>=0)
.flatMap(x => x.catch(err => Observable.just({err})))
.map(response => {
if(isErr(response)){
return extractError(response)
}
else{
return extractResponse(response)
}
})
const x$ = response$.filter(x => x.status === "success").map(x => {return {key: "b", value: x.session.b_token}})
main function:
const loginStorage$ = sources.http
.filter(res => res.request.url.indexOf("test/v3/users/login")>=0)
.flatMap(x => x.catch(err => Observable.just({err})))
.map(response => {
if(isErr(response)){
return extractError(response)
}
else{
return extractResponse(response)
}
})
.filter(x => x.status === 'success').map(x => {return {key: "a", value: x.session.id}})
Any help appreciated!!

Related

How to override this function to store data in DB?

In BroadcastServiceProvider.php I've got data when user joins the channel and I would like to store it to DB. I am wondering how to override this storeUser() function to make it work (I've used this function before but it was in other circumstances).
public function storeUser() {
UserInfo::create([
'ip' => Request::ip(),
'name' => Auth::user()->name
]);
}
BroadcastServiceProvider.php
Broadcast::channel('chat', function ($user) {
$ip = Request::ip();
if (auth()->check()) {
return [
'id' => $user->id,
'ip' => $ip,
'name' => $user->name
];
}
});
Update the UserInfo model to have the storeUser method.
class UserInfo
{
public static function storeUser() {
UserInfo::create([
'ip' => Request::ip(),
'name' => Auth::user()->name
]);
}
Then you can call it in the broadcaster
Broadcast::channel('chat', function ($user) {
$ip = Request::ip();
if (auth()->check()) {
UserInfo::storeUser();
return [
'id' => $user->id,
'ip' => $ip,
'name' => $user->name
];
}
});
You can also call it in the same way UserInfo::storeUser(); in the users controller where ever you need it.

Using RabbitMQ fields in Logstash output

I want to use some fields from RabbitMQ messages into Logstah Elasticsearch output (like a index name, etc).
If I use [#metadata][rabbitmq_properties][timestamp] in filter it works nice, but not in output statement (config below).
What am I doing wrong?
input {
rabbitmq {
host => "rabbitmq:5672"
user => "user"
password => "password"
queue => "queue "
durable => true
prefetch_count => 1
threads => 3
ack => true
metadata_enabled => true
}
}
filter {
if [#metadata][rabbitmq_properties][timestamp] {
date {
match => ["[#metadata][rabbitmq_properties][timestamp]", "UNIX"]
}
}
}
output {
elasticsearch {
hosts => ['http://elasticsearch:9200']
index => "%{[#metadata][rabbitmq_properties][IndexName]}_%{+YYYY.MM.dd}"
}
stdout {codec => rubydebug}
}
check with replace function as mentioned below.
input {
rabbitmq {
host => "rabbitmq:5672"
user => "user"
password => "password"
queue => "queue "
durable => true
prefetch_count => 1
threads => 3
ack => true
metadata_enabled => true
}
}
filter {
if [#metadata][rabbitmq_properties][timestamp] {
date {
match => ["[#metadata][rabbitmq_properties][timestamp]", "UNIX"]
}
}
mutate {
replace => {
"[#metadata][index]" => "%{[#metadata][rabbitmq_properties][IndexName]}_%{+YYYY.MM.dd}"
}
}
}
output {
elasticsearch {
hosts => ['http://elasticsearch:9200']
index => "%{[#metadata][index]}_%{+YYYY.MM.dd}"
}
stdout {codec => rubydebug}
}

SQL query for restoring the latest revision on all posts in wordpress

My wordpress site recently got attacked and all the posts seem to have been updated with a blank version. So I want to restore the most latest revision for all posts. (NB: In wordpress the current published version is also stored in the database as a revision. So I think I would need to restore the 2nd revision (when arranged in the descending order))
What would be the SQL query for that?
Any help would be greatly appreciated!
So, all you need is in your database (luckily). The posts themselves can be retrieved like this
global $wpdb;
$query = "SELECT * FROM wp_posts WHERE post_type = 'revision'";
$query_results = $wpdb->get_results($query, ARRAY_A);
foreach ($query_results as $q_key => $q_value) {
$post = array(
'post_content' => $q_value['post_content']
'post_name' => $q_value['post_name']
'post_title' => $q_value['post_title']
'post_status' => $q_value['post_status']
'post_type' => 'post'
'post_author' => $q_value['post_author']
'ping_status' => $q_value['ping_status']
'post_parent' => $q_value['post_parent']
'menu_order' => $q_value['menu_order']
'to_ping' => $q_value['to_ping']
'pinged' => $q_value['pinged']
'post_password' => $q_value['post_password']
'guid' => $q_value['guid']
'post_content_filtered' => $q_value['post_content_filtered']
'post_excerpt' => $q_value['post_excerpt']
'post_date' => $q_value['post_date']
'post_date_gmt' => $q_value['post_date_gmt']
'comment_status' => $q_value['comment_status']
);
wp_insert_post( $post );
}
Read about wp_insert_post() here.
Now, depending on how much posts you have, this can either take a while, or it can break. If it breaks, then you'll need to wrap this in a function that you'll call with AJAX. Something like this should do the trick:
add_action( 'wp_ajax_insert_posts', 'database_ajax_insert_posts' );
add_action( 'wp_ajax_nopriv_insert_posts', 'database_ajax_insert_posts' );
function database_ajax_insert_posts(){
global $wpdb;
$offset = $_POST['offset'];
$query = "SELECT * FROM wp_posts WHERE post_type = 'revision' LIMIT $offset, 1";
$query_results = $wpdb->get_results($query, ARRAY_A);
foreach ($query_results as $q_key => $q_value) {
$post = array(
'post_content' => $q_value['post_content']
'post_name' => $q_value['post_name']
'post_title' => $q_value['post_title']
'post_status' => $q_value['post_status']
'post_type' => 'post'
'post_author' => $q_value['post_author']
'ping_status' => $q_value['ping_status']
'post_parent' => $q_value['post_parent']
'menu_order' => $q_value['menu_order']
'to_ping' => $q_value['to_ping']
'pinged' => $q_value['pinged']
'post_password' => $q_value['post_password']
'guid' => $q_value['guid']
'post_content_filtered' => $q_value['post_content_filtered']
'post_excerpt' => $q_value['post_excerpt']
'post_date' => $q_value['post_date']
'post_date_gmt' => $q_value['post_date_gmt']
'comment_status' => $q_value['comment_status']
);
wp_insert_post( $post );
}
}
And AJAX
jQuery(document).ready(function($) {
"use strict";
var offset = 1;
function ajax_call(){
$.ajax({
type: "POST",
url: ajaxurl,
data: {
'action': 'insert_posts',
'offset': offset,
},
success: function(response) {
if (offset < 100){ //Number of posts go here
offset += 1;
ajax_call();
} else{
$('#wpbody-content').append('<p>All done!</p>' );
}
},
error : function (jqXHR, textStatus, errorThrown) {
$('#wpbody-content').html(jqXHR + ' :: ' + textStatus + ' :: ' + errorThrown);
}
});
}
ajax_call();
});
Also be sure to localize your AJAX url with the handle of the script in which you'll put your AJAX call.
wp_localize_script('your_handle', 'db_from_WP', array(
'ajaxurl' => admin_url( 'admin-ajax.php' )
));
Taxonomy should be in the database, and you could get them in a similar fashion.
This is not foolproof, but should work. The thing that I can see that could be a bit problematic is getting the right taxonomy for the post, but that is doable, although with a bit fiddling around.
Hope this helps.

How to specify Schema for Lists while mapping Nhibernate by code

I want my "tag_post" table to be created in "article" schema but it's created in "public" schema.
List(x => x.Tags, l =>
{
l.Where("deleted = 0");
l.Key(k =>
{
k.Column("post_id");
k.NotNullable(true);
});
Schema(Constants.DatabaseSchemaNames.Article);
l.Table("tag_post");
}, x =>
{
x.ManyToMany(m => m.Column("tag_id"));
});
I have never used mapping by code, but i assume this is the solution:
List(x => x.Students, l =>
{
l.Where("deleted = 0");
l.Key(k =>
{
k.Column("post_id");
k.NotNullable(true);
});
l.Schema(Constants.DatabaseSchemaNames.Article);
l.Table("tag_post");
}, x =>
{
x.ManyToMany(m => m.Column("tag_id"));
});

fill kendo combo box parameter

I have a kendo combobox Clients, and I fill his content with
.DataSource(
source =>
{
source.Read(read => { read.Action("GetAllClientsJSONCombo", "CrmCProfile"); });
})
Now, I have another kendo combobox ContactsClient, but I need pass the Id of the selected client in first combobox, like this:
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetAllContactsClientJSONCombo", "CrmCProfile", new object { Id_Cliente = (????????)});
})
.ServerFiltering(false);
})
Thanks.
It is fine if you dont write new object just specify the word new
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetAllContactsClientJSONCombo", "CrmCProfile", new { Id_Cliente = Model.Value});
})
.ServerFiltering(false);
})
OR
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetAllContactsClientJSONCombo", "CrmCProfile").Data("yourParameters");
})
.ServerFiltering(false);
})
<script>
function yourParameters(){
return {"Id_Cliente": yourParameterValue};
}
</script>
And make sure that on the server side, the name of the parameter (i.e, Id_Cliente) is same.
public JsonResult GetAllContactsClientJSONCombo(string Id_Cliente){
//your logic here
}