ModX getResource stopped working - mysql

I can't get a result with getResource anymore.
For example, I want to query my blog posts:
My articles are created with the Articles plugin.
In my template, I have:
[[!getResources:ifempty=`No Resource`? &parents=`33` &showHidden=`1` ]]
It simply shows "No Resource".
Without the ifempty tag, it simply doesn't show anything.
The weird thing is I know I have those articles in my database. When I try with the parameter debug=true, I see the article objects' dump in place of the template. So the query is working fine, getResource retrieves the articles when debug is set to true!
With debug, I can see the SQL query in my log file:
[2014-02-10 16:58:37] (ERROR # /huayang/index.php) context for 33 is
web
[2014-02-10 16:58:37] (ERROR # /huayang/index.php) SELECT modResource.id, modResource.type, modResource.contentType,
modResource.pagetitle, modResource.longtitle,
modResource.description, modResource.alias,
modResource.link_attributes, modResource.published,
modResource.pub_date, modResource.unpub_date,
modResource.parent, modResource.isfolder,
modResource.introtext, modResource.richtext,
modResource.template, modResource.menuindex,
modResource.searchable, modResource.cacheable,
modResource.createdby, modResource.createdon,
modResource.editedby, modResource.editedon,
modResource.deleted, modResource.deletedon,
modResource.deletedby, modResource.publishedon,
modResource.publishedby, modResource.menutitle,
modResource.donthit, modResource.privateweb,
modResource.privatemgr, modResource.content_dispo,
modResource.hidemenu, modResource.class_key,
modResource.context_key, modResource.content_type,
modResource.uri, modResource.uri_override,
modResource.hide_children_in_tree, modResource.show_in_tree,
modResource.properties FROM modx_site_content AS modResource
WHERE ( modResource.parent IN (33,34,35,36) AND
modResource.deleted = 0 AND modResource.published = 1 ) ORDER
BY publishedon DESC LIMIT 5
When I run this query directly in phpmyadmin, I get the articles!
To be clear, getResource simply won't work whatever the query I try to make, if debug isn't set to true. It won't show my any error at any point..
I have already uninstalled and reinstalled the plugin.
So.. any idea how I can fix this? Any suggestion how I should proceed to debug this?
Edit: getresources-1.6.1-pl
Edit2:
Started debugging, snippet.getresources.php, line 430
$collection = $modx->getCollection('modResource', $criteria, $dbCacheFlag);
$collection is an empt array..
$criteria is a xPDOQuery_mysql Object which looks correct..
I'm gonna sleep through this and will reinstall ModX tomorrow if I can't fix this

The issue was that my template was in Templates instead of Chunks, the snippet started working again after I moved articlePreview into Chunks.
Some kind of output would have helped..
Hope this can help someone.

Related

Query unexpectedly fails

I am creating a simple member system using MySQL, and have stumbled onto a problem.
The issue is that I am using the correct SQL query to search the column Username, and find Administrator, but however my query isn't finding anything.
I have searched the internet for a solution (with many results taking my back to Stack Overflow), but however have not found anything.
The query that I am using is:
SELECT * FROM members WHERE Username = "Administrator"
Which looks find from my end, but however does not return any results:
Am I doing something wrong here?
I am new to MySQL & PHP, so if something is obviously wrong with what I'm doing here, please tell me nicely, and please don't 'flame'.
Edit:
When attempting to run this query though PHP, I get:
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /home/crysisor/public_html/checklogin.php on line 22
The above code confirms that something is wrong...
Relevant code:
$user = mysqli_real_escape_string($sqli, $_POST['user']);
$pass = mysqli_real_escape_string($sqli, $_POST['pass']);
if ($user && $pass) {
$checkuser= mysqli_num_rows(mysqli_query($sqli, "SELECT * FROM users WHERE Username='".$user."'"));
I have a few hints which may help you resolve your problem.
Make the query itself a PHP variable, and echo it. Then copy and paste the echoed result into phpMyAdmin.
Use single quotes for query variables. The query itself should be in double quotes.
Unrelated: the password looks short. It shouldn't be stored in plain text.

CakePHP Error: SQLSTATE[42S02] table not found - but exist

You might read this question every day so i tried another Stackoverflow's answer before asking:
CakePHP table is missing even when it exists
Anyways. The table i try to select data from does exist (quadra-checked uppercase/lowercase!) and it gets also listed via $db->->listSources().
Here's a screenshot of the query, the message and the last result from listing all Datasource's tables:
http://i.stack.imgur.com/CdhcV.png
Note: If i run this query in PHPMyAdmin manually it works fine. I would say its impossible to get the pictures output at one time in a view - now its up to you to tell me the opposite. By the way: I am pretty sure to use the correct Datasource.
I should tell additionally that the mysql-server is hosted on another platform. Since i can use it for my localhost-phpmyadmin if i modify the config.inc.php i can promise it is no Firewall-Problem.
Written in behalf of xcy7e:
The mistake was to execute the Query from the local Model. Here's the code:
$conn = ConnectionManager::getDataSource('myDB');
$conn->query($query);
// instead of $this->query($query);

Get Redmine custom field value to a file

I'm trying to create a text file that contains the value of a custom field I added on redmine. I tried to get it from an SQL query in the create method of the project_controller.rb (at line 80 on redmine 1.2.0) as follows :
sql = Mysql.new('localhost','root','pass','bitnami_redmine')
rq = sql.query("SELECT value
FROM custom_values
INNER JOIN projects
ON custom_values.customized_id=projects.id
WHERE custom_values.custom_field_id=7
AND projects.name='#{#project.name}'")
rq.each_hash { |h|
File.open('pleasework.txt', 'w') { |myfile|
myfile.write(h['value'])
}
}
sql.close
This works fine if I test it in a separate file (with an existing project name instead of #project.name) so it may be a syntax issue but I can't find what it is. I'd also be glad to hear any other solution to get that value.
Thanks !
(there's a very similar post here but none of the solutions actually worked)
First, you could use Project.connection.query instead of your own Mysql instance. Second, I would try to log the SQL RAILS_DEFAULT_LOGGER.info "SELECT ..." and check if it's ok... And the third, I would use identifier instead of name.
I ended up simply using params["project"]["custom_field_values"]["x"] where x is the custom field's id. I still don't know why the sql query didn't work but well, this is much simpler and faster.

CI: Session Variables and json_encode

I have values I've added to my session that I'd like to pass into an query as follows:
$eventTypeID = $this->session->userdata('eventtypeID');
$this->session->unset_userdata('eventtypeID');
$venueCityID = $this->session->userdata('venuecityID');
$this->session->unset_userdata('venuecityID');
echo json_encode($this->event_model->getSearchEvents($eventTypeID, $venueCityID));
The issue I'm running into is that last line (echo json_encode...) will not run when the prior variables are extracted/unset. If I comment out the variables, and run simply:
echo json_encode($this->event_model->getSearchEventsAll());
Then all works well. Can someone tell my why json_encode doesn't seem to play well with sessions and how I may be able to get this to work? Thanks!
EDITED
After much frustration, it now appears the issue may not be with the session, but is instead with outputting my query:
$this->db->_compile_select();
$q = $this->db->get();
echo $this->db->last_query();
All used to work fine, and I was able to "intercept" the query to see what was being called, but now when using _compile & last_query, nothing happens????
Run json_last_error() to see if any errors were encountered encoding the data. See the example on the docs page for proper usage:
http://www.php.net/manual/en/function.json-last-error.php
We're not certain what $this->event_model->getSearchEvents($eventTypeID, $venueCityID) returns VS $this->event_model->getSearchEvents(), but there should definitely not be any problems related to the use of variables.
As always, try var_dump() on the output (try before decoding) and see what the differences are between the two return values of the function. You might even be encountering an error within the function itself that's stopping execution - make sure error_reporting() is on full-blast.

MySQL / SQLite3

I stumbled upon the following:
def save_formset(self, request, form, formset, change):
instances = formset.save(commit=False)
bargain_id = 0
total_price = Decimal(0)
for instance in instances:
if isinstance(instance, BargainProduct):
total_price += instance.quantity * instance.product.price
bargain_id = instance.id
instance.save()
updateTotal = Bargain.objects.get(id=bargain_id)
updateTotal.total_price = total_price - updateTotal.discount_price
updateTotal.save()
This code is working for me on my local MySQL setup, however, on my live test enviroment running on SQLite3* I get the "Bargain matching query does not exist." error..
I am figuring this is due to a different hierarchy of saving the instances on SQLite.. however it seems they run(and should) act the same..?
*I cannot recompile MySQL with python support on my liveserver atm so thats a no go
Looking at the code, if you have no instances coming out of the formset.save(), bargain_id will be 0 when it gets down to the Bargain.objects.get(id=bargain_id) line, since it will skip over the for loop. If it is 0, I'm guessing it will fail with the error you are seeing.
You might want to check to see if the values are getting stored correctly in the database during your formset.save() and it is returning something back to instances.
This line is giving the error:
updateTotal = Bargain.objects.get(id=bargain_id)
which most probably is because of this line:
instances = formset.save(commit=False)
Did you define a save() method for the formset? Because it doesn't seen to have one built-in. You save it by accessing what formset.cleaned_data returns as the django docs say.
edit: I correct myself, it actually has a save() method based on this page.
I've been looking at this same issue. It is saving the data to the database, and the formset is filled. The problem is that the save on instances = formset.save(commit=False) doesn't return a value. When I look at the built-in save method, it should give back the saved data.
Another weird thing about this, is that it seems to work on my friends MySQL backend, but not on his SQLITE3 backend. Next to that it doesn't work on my MySQL backend.
Local loop returns these print outs (on MySQL).. on sqlite3 it fails with a does not excist on the query
('Formset: ', <django.forms.formsets.BargainProductFormFormSet object at 0x101fe3790>)
('Instances: ', [<BargainProduct: BargainProduct object>])
[18/Apr/2011 14:46:20] "POST /admin/shop/deal/add/ HTTP/1.1" 302 0