Joomla JFactory Class in module - joomla

I made a module which after receive &_POST the details from external server will select the tables from database and update the table cell. but: Between the 'if' statement, the jFactory Class is not working i mean i can not call username using $user->username but if i call the $user->username before the 'if' statement everything works fine. Could you help me with this and tell why its not working correctly
if($_SERVER['REMOTE_ADDR']=='IP NUMBER' && !empty($_POST)){
$xxx = $_POST['xxx'];
$zzz = $_POST['zzz'];
$yyy = $_POST['yyy'];
}
The post variables are received from external server
Have you any idea ?
I need to add that $_post from the exterran server is receive with a delay but module is active all time..

Related

Laravel 502 Proxy Error on specific route call

I am having a problem specific to the production code. On said server, everytime I try to access specific route which is supposed to show a table of all categories I get a 502 Proxy Error:
Proxy Error
The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request
Reason: Error reading from remote server
I have found some common problem on the internet already, however all of those were for users who use nginx. I use Laragon. Also, Laravel version is 5.5.21
As I said the problem is production code only. It is not happening when I run it locally.
I also tried to download laravel.log file from the server, but there was nothing there.
This is the function that is being called by route:
public function index(){
if(empty(request()->query()) && session()->exists('categories_filter')){
return redirect(route('categories.index').'?'.http_build_query(session()->pull('categories_filter')));
}
if(!empty(request()->query())){
$this->store_filter();
}
$categories = Category::orderBy($this->sort, $this->order);
if($name_sk = request('name_sk')){
$categories = $categories->where('name_sk', 'like', "%{$name_sk}%");
}
$categories = $categories->paginate(20);
$all_categories = Category::with('children')->get();
$sort = $this->sort;
$order = $this->order;
$new_order = $this->new_order;
return view('admin.categories.index', compact('categories', 'sort', 'order', 'new_order', 'all_categories'));
}
I honestly have no idea where the problem lies or what is its cause.
So to the people who have a similar problem, here is where my problem was:
I had a recursive blade partial component, that called itself and in every single one of those there was a sql query executed. I had to completely remake that part of my view.
So to explain it, the reason for this error is simply that I was sending too many requests to the database asking for a single row. This was a problem because once there was a moderate amount of data, it was simply taking way too long to load.

Laravel - OutputStyle from jobs

I'm running into issues with allowing a Laravel job to interact with the console output.
At the moment I am passing in the OutputStyle from a Command to the Job constructor and assigning it.
I have seen the InteractsWithIO trait but if I use that by itself without assigning the OutputStyle from the command then it says it is null.
Call to a member function title() on null
I have also tried setting $this->output from the container using
$this->output = resolve(OutputStyle::class);
This fails with a
Target [Symfony\Component\Console\Input\InputInterface] is not instantiable while building [Illuminate\Console\OutputStyle].
I've also ran into issues with PHPUnit tests that run through this job. The output from the class is displayed in the test output.
.......................Processing element 1 for "Section"
.......
What's the best way to handle outputting to the console within Laravel that also works with PHPUnit?
Putting the following code in a Service Provider works:
$this->app->bind('console.output', function () {
return new OutputStyle(
new StringInput(''),
new StreamOutput(fopen('php://stdout', 'w'))
);
});
I am then able to say, in my Job,
$this->output = resolve('console.output');
Which gives access to all the methods such as title, section, and table.

Unable to update ShopifyAPI::Collect object using Ruby script

I am working on a shopify app in which I want to run a script which is in Ruby. I want to update the 'position' and 'sort_value' of Collect object as per this link https://docs.shopify.com/api/collect. Everytime I try to do so I got an ActiveResource Error.
Here is my code in irb:
require 'shopify'
require 'active_resource'
shop_url = "https://#{API_KEY}:{PASSWORD}#SHOP_NAME.myshopify.com/admin"
ShopifyAPI::Base.site = shop_url
product = ShopifyAPI::Collect.find(:id)
product.position = 4
product.save
I have tried the code given below, which works fine in irb
product = ShopifyAPI::Product.find(179761209)
product.handle = "burton-snowboard"
product.save
I got this error:
ActiveResource::ResourceNotFound: Failed. Response code = 404. Response message = Not Found
Can we send http PUT request on Collect object to update position? Thanks in Advance..
It appears you are not providing any ID to your call.
product = ShopifyAPI::Collect.find(:id)
What is that supposed to return?
I think you have a 404 returned it is a good indication you are not asking for something with a valid ID. Your second call works fine with an ID.

How does a Meteor database mutator know if it's being called from a Meteor.method vs. normal code?

If one does something on the client like
Foo.insert({blah : 1})
where Foo is a Meteor collection, this actually triggers a Meteor.method call as documented in the last paragraph of http://docs.meteor.com/#meteor_methods that executes code on both the client and the server.
However, let's say I define a method (on client and server) that does the same thing:
Meteor.methods({
bar: function() {
Foo.insert({blah : 1})
}
});
Now, I trigger this on the client with
Meteor.call("bar");
Foo.insert will now be called both on the client and the server as a result of the method. However, how does the client-side invocation of insert know not to call the server again, since it is itself a method?
Moreover, is there a way to call insert on the client side without automatically triggering the canonical server-side latency-compensation call and resulting synchronization? (For why I'd want to do this, see Loading a Meteor client app with fake fire-and-forget data)
The client side one becomes a 'stub'. It has this isSimulation property set that makes it appear as if the data is inserted for latency compensation.
I think if a .method is run on the client the latency compensation is always enabled and it shouldn't enter in the database. So anything running on a client side method would be a 'fake' type simulation
If you try setting this.isSimulation to false you'll get some weird error that shows you that the client side insert starts to throw errors with the insert.
I'm not too sure how to run it in a false simulation. I think you'd have to run it off in some other method var dothis = function() {...} type method.
To do this 'fake fire' & forget and have client side only data, which is what I presume (please correct if I'm wrong so I change the answer) modify the _collection property in your client side method.
e.g if you have
mydata = new Meteor.Collection("something");
function something() {
mydata.insert({..});
}
Modify the method to do this instead
mydata._collection.insert({..});
This will make sure that the data isn't synchronized to the server, yet will have the local collection have this 'fake data'.
Hope this helps!

Facebook ajax losing session

I'm trying to develop a Facebook app but am hitting a problem with session variables.
I call a script via ajax which sets a session variable.
Later, I call a script via ajax which retrieves the previously set session variable, but the variable is empty.
The first script called when the app loads in index.php.
I have the following at the top
<?php
session_start();
//Get PHP SDK
require_once 'facebook-php-sdk/src/facebook.php';
// Create our Application instance.
$facebook = new Facebook( array('appId' => 'xxxxxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'cookie' => true, ));
$signed_request = $facebook -> getSignedRequest();
$like_status = $signed_request["page"]["liked"];
?>
The first script called via ajax sets the session variable like this:
$numbers = range(1, 52);
shuffle($numbers);
$_SESSION['cards'] = serialize($numbers);
The second script (which is called about 10 seconds later,so I don't think it will be a race problem) looks like this:
$numbers = unserialize($_SESSION['cards']);
The variable $numbers is empty even though no other script has emptied $_SESSION['cards'].
Should this work or am I doing it wrong? I'm very new to ajax.
I've read there can be problems with ajax calls in an iframe which is the way the facebook app is set up but I haven't managed to find a resolution.
Anyone know how to fix this?
you must call session_start() on both index.php and ajax script to share same session

Resources