How to find out Joomla JTable column/field names? - joomla

I'm using Joomla 2.5 to build a medium-sized website, and I've decided to ease maintenance and content management headaches through creating menus automatically.
I've looked for extensions which did this, but only found Joomla 1.5 extensions. I ended up trying to upgrade a GPL extension called Auto Menu Magic.
It was easy to deal with the basic issues like the XML tags in the extension file, since there's a page in the Joomla which helps you migrate from Joomla 1.5 to 1.6.
The extension I mentioned has a function named onContentAfterSave which is called by joomla when an article is saved. I've been debugging through creating rubbish articles in the admin interface and changing the code to throw exceptions in several places, which I can see as error messages on the admin frontend.
This is where I got stuck:
$db = &JFactory::getDBO();
$menu = JTable::getInstance( 'menu');
$menu->menutype = $menutype;
$menu->name = $name;
$menu->link = $link;
$menu->type = $linktype;
$menu->published = $published;
$menu->componentid = $componentid;
$menu->parent = $menuparentid;
$menu->sublevel = $menusublevel;
$menu->checked_out = 0;
$menu->checked_out_time = 0;
$menu->pollid = 0;
$menu->browserNav = 0;
$menu->access = 0;
$menu->utaccess = 0;
$menu->lft = 0;
$menu->rgt = 0;
$menu->home = 0;
$menu->params = $params;
// Figure out the order (Just pop this article at the end of the list):
$menu->ordering = $menu->getNextOrder(
"menutype = ".$db->Quote($menu->menutype).
" AND published >= 0 AND parent = ".(int) $menu->parent
);
// Validate:
if (!$menu->check())
return NULL;
// DEBUG 2 -- Integrity check
throw new Exception ("menutype: $menutype, name: $name, link: $link published: $published, componentid: $componentid menuparentid: $menuparentid menusublevel: $menusublevel");
// Save:
if (!$menu->store())
return NULL;
// DEBUG 1
throw new Exception(" Could save! ");
As you can see above, I tried to throw an exception (DEBUG 1) when the menu was saved to the database. This exception was never reached, but the upper exception (DEBUG 2) is reached. This means that $menu->check() returns true, but not $menu->store(). I assume that the database is returning an error because some of the Joomla database structure might have changed after 1.5.
I have read the source a lot these past hours, but I can't find one thing. How can I look at the columns that a Joomla table uses, so I can debug this error properly?
Thanks in advance!
PS: I've looked at the SQL database too, but it doesn't help much. The variables seem to have different naming conventions from the column names.

I think it should look like this because I have been trying to convert auto menu as well!
$db = &JFactory::getDBO();
$menu = JTable::getInstance('menu');
$menu->menutype = $menutype;
$menu->title = $title;
$menu->alias = strtolower($title) ;
$menu->note = "Created by automenu";
$menu->path = $link;
$menu->link = $link;
$menu->type = $linktype;
$menu->published = $published;
$menu->parent_id = $menuparentid
$menu->level = $menusublevel;
$menu->componentid = $componentid;
$menu->ordering = 0;
$menu->checked_out = 0;
$menu->checked_out_time = 0;
$menu->browserNav = 0;
$menu->access = 1;
$menu->img = '';
$menu->templat_style_id = 0;
$menu->params = $params;
$menu->lft = 0;
$menu->rgt = 0;
$menu->home = 0;
$menu->language = '*';
$menu->client_id = 0;
I would be interseted to know if you ever got it working!

I'd suggest turning on Joomla debugging in the System Configuration. At the bottom of each page it shows all the queries it has executed, and this (depending on the plugin) might show you what SQL is being executed, and presumably, failing. There's likely to be a big list, so you may have to search through it a bit to find the statement you're interested in.

Fabio,
Many thanks! I will try it out and see if I can improve it further.
Mike

You're forgetting the first rule of Exceptions Club, if you throw something... you have to catch it.
I don't see a try/catch pair in your code so PHP would be stopping with a "Fatal Error..." for the uncaught exception so it would never get to the DEBUG 1. e.g.
Fatal error: Uncaught exception 'Exception' with message ...
Try wrapping your code in a try/catch pair and allowing the execution to continue after DEBUG 2 have a look at the PHP doc's for exceptions

Related

Code.org's AppLab readRecords function problem

I call readRecords on line 74 and the syntax is simple, but the program hangs at this line. The Students table exists, with 12 students, it was originally created with the createRecord on line
60. I've looked at the syntax for this line for tooooo long. What am I missing?
Also, is there a more elegant way to use this data outside of the readRecords code block? I'm copying it to arrays (no 2-dimensional arrays or structures in applab). I tried to create a global 'records' of some kind, without success. The App Lab project examples I learned from use the data within the readRecords code block, but not outside the block.
The project:
my project: https://studio.code.org/projects/applab/xEEOqp8zpOJ2g-YyCntajlhvh0crb2ysLvP1Pg5LCF8
The specific code:
onEvent("choosePeriodNext", "click", function() {
var chosenPeriod = getText("period2");
readRecords("Students", {}, function(records) {
numStudents = records.length;
if (numStudents>0) {
for (var i =0; i < numStudents; i++) {
console.log (records[i].goesBy);
goesBys[i] = records[i].goesBy;
pronounss[i] = records[i].pronouns;
periods[i] = records[i].period;
firsts[i] = records[i].first;
lasts[i] = records[i].last;
games[i] = records[i].game;
jobs[i] = records[i].job;
goodAts[i] = records[i].goodAt;
toKnows[i] = records[i].toKnow;
photos[i] = records[i].photo;
}
learnNames();
} else setScreen ("home");
});
});
Thank you for your help!
Carol
I answered my own question.
I found that this code worked in a collegue's browser, but not mine.
I cleared cache and cookies, then restarted my browser. Now it works.
Oh my.

Why recent project and solution pinned always is false?

I'm writing a extension package for VS 2019, So far i find out how to get "Recent projects and solutions" items, These items have a PropertyInfo called "Pinned" which means that project or solution is pinned, Except it's always false.
Here is the code which i get project list and show it to user :
IVsDataSourceFactory objFactory = serviceProvider.GetService(typeof(SVsDataSourceFactory)) as IVsDataSourceFactory;
objFactory.GetDataSource(new Guid("9099ad98-3136-4aca-a9ac-7eeeaee51dca"), 1, out IVsUIDataSource dataSource);
Type typProjectMruList = Type.GetType("Microsoft.VisualStudio.PlatformUI.ProjectMruList, Microsoft.VisualStudio.Shell.UI.Internal", true);
System.Reflection.PropertyInfo itemsProperty = typProjectMruList.GetProperty("Items");
Type typFileSystemMruItem = Type.GetType("Microsoft.VisualStudio.PlatformUI.FileSystemMruItem, Microsoft.VisualStudio.Shell.UI.Internal", true);
System.Reflection.PropertyInfo pathProperty = typFileSystemMruItem.GetProperty("Path");
System.Reflection.PropertyInfo pinnedProperty = typFileSystemMruItem.GetProperty("Pinned");
IList lstItems = (IList)itemsProperty.GetValue(dataSource, null);
string strMsg = "";
for (var i = lstItems.Count - 1; i > -1; i--)
{
string strPath = (string)pathProperty.GetValue(lstItems[i], null);
bool blnPinned = (bool)pinnedProperty.GetValue(lstItems[i], null);
strMsg = strMsg + "Path : " + strPath + Environment.NewLine + "Pinned : " + blnPinned.ToString() + Environment.NewLine + Environment.NewLine;
}
// Show a message box to prove we were here
VsShellUtilities.ShowMessageBox(
package,
strMsg,
"",
OLEMSGICON.OLEMSGICON_INFO,
OLEMSGBUTTON.OLEMSGBUTTON_OK,
OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
Anyone tried to do something like this before? Or this is a bug and i should report it to microsoft?
If you want to test this code just create a new command and put this code in "Execute" void.
Anyone tried to do something like this before? Or this is a bug and i
should report it to microsoft?
Based on your description, when I try your code and when I debug this project, create a new project in solution explorer, I faced the same issue as you said: the value of blnPinned is always false though the project is pinned.
So l have reported this issue on our DC Forum for you. See this link which I hope anyone who is interested in this issue will vote for you.
You can vote on this issue and add any comment if I forgot some detailed info to attract more attention. With this further step, I hope the staff will give a satisfactory feedback.

Pushing Offline Leads using Adwords API

I am using the below function to push my offline leads to api, everything looks good and returns success but when I check adwords, it doesnt show any data saying it received. I have tried many leads and also waited for around 3-4 days now.
What am I doing wrong?
function UploadOfflineConversionsExample(AdWordsUser $user, $conversionName,$gClId, $conversionTime, $conversionValue)
{
// Get the services, which loads the required classes.
// $conversionTrackerService = $user->GetService('ConversionTrackerService', ADWORDS_VERSION);
$offlineConversionService = $user->GetService('OfflineConversionFeedService', ADWORDS_VERSION);
// Associate offline conversions with the upload conversion we created.
$feed = new OfflineConversionFeed();
$feed->conversionName = $conversionName;
$feed->conversionTime = $conversionTime;
$feed->conversionValue = $conversionValue;
$feed->googleClickId = $gClId;
$offlineConversionOperation = new OfflineConversionFeedOperation();
$offlineConversionOperation->operator = 'ADD';
$offlineConversionOperation->operand = $feed;
$offlineConversionOperations = array($offlineConversionOperation);
$result = $offlineConversionService->mutate($offlineConversionOperations);
$feed = $result->value[0];
return ("Uploaded offline conversion value of ". $feed->conversionValue.
" for Google Click ID = ". $feed->googleClickId." and Conversion Name " . $feed->conversionName);
}
In adwords reports this conversion will be shown in Conversions Column. and change the daterange to the date what you pushed as $conversionTime

What is the meaning of null in Mage log (magento)?

In order to create Magento log, one would write something like
Mage::log('Server Side Validation kicked in for Year for '.$currentYearType);
But if I were to add the log in a sepearate file , do I
Mage::log('Server Side Validation kicked in for Year for ' ,null,'serversidevalidation.log');
Please correct me if I am wrong.
If so, what is the use of null in the middle?
Also, does the file need to exist before hand or I think it is created by system when needed. Am I right? Also, will it include timestamp?
Go to to app/Mage.php
line 785
public static function log($message, $level = null, $file = '', $forceLog = false)
you can see the second paramete is level
$level = is_null($level) ? Zend_Log::DEBUG : $level;
lib\Zend\log.php
const EMERG = 0; // Emergency: system is unusable
const ALERT = 1; // Alert: action must be taken immediately
const CRIT = 2; // Critical: critical conditions
const ERR = 3; // Error: error conditions
const WARN = 4; // Warning: warning conditions
const NOTICE = 5; // Notice: normal but significant condition
const INFO = 6; // Informational: informational messages
const DEBUG = 7; // Debug: debug messages
if you this code Mage::log('test', 1);
then you get a output in log file like this
2014-05-17T12:21:51+00:00 ALERT (1): test
Yes, the file is automatically created by system when its call
system include the timestamp when it call
refer this code in app/Mage.php in line 825
$format = '%timestamp% %priorityName% (%priority%): %message%' . PHP_EOL;
$formatter = new Zend_Log_Formatter_Simple($format);
Cheers

PHP parse error in rss parse function

I have a client who needs a website urgently, but I have no access to information such as the control panel.
PHP Version is 4.4 Which is a pain as I'm used to 5.
The first problem is I keep getting:
Parse error: parse error, unexpected T_OBJECT_OPERATOR, expecting ')' in D:\hshome\*******\********\includes\functions.php on line 37
This is the function in question:
function read_rss($display=0,$url='') {
$doc = new DOMDocument();
$doc->load($url);
$itemArr = array();
foreach ($doc->getElementsByTagName('item') as $node) {
if ($display == 0) {
break;
}
$itemRSS = array(
'title'=>$node->getElementsByTagName('title')->item(0)->nodeValue,
'description'=>$node->getElementsByTagName('description')->item(0)->nodeValue,
'link'=>$node->getElementsByTagName('link')->item(0)->nodeValue);
array_push($itemArr, $itemRSS);
$display--;
}
return $itemArr;
}
And the line in question:
'title'=>$node->getElementsByTagName('title')->item(0)->nodeValue,
PHP4 does not support object dereferencing. So $obj->something()->something will not work. You need to do $tmp = $obj->something(); $tmp->something...
You can't do that in PHP 4.
Have to do something like
$nodes = $node->getElementsByTagName('title');
$item = $nodes->item(0);
$value = $item->nodeValue,
Try it and it will work.
You can't chain object calls in PHP 4. You're going to have to make each call separately to a variable and store it all.
$titleobj = $node->getElementsByTagName('title');
$itemobj = $titleobj->item(0);
$value = $itemobj->nodeValue;
...
'title'=>$value,
you'll have to do it on all those chained calls
As for .htaccess ... you need to talk to someone who controls the actual server. It sounds like .htaccess isn't allowed to change the setting you're trying to change.
You need to break down that line into individual variables. PHP 4 does not like -> following parentheses. Do this instead:
$title = $node->getElementsByTagName('title');
$title = $title->item(0);
$description = $node->getElementsByTagName('description');
$description = $description->item(0);
$link = $node->getElementsByTagName('link');
$link = $link->item(0);
$itemRSS = array(
'title'=>$title->nodeValue,
'description'=>$description->nodeValue,
'link'=>$link->nodeValue);
The two variable declarations for each may be redundant and condensed, I'm not sure how PHP4 will respond. You can try to condense them if you want.
DOMDocument is php 5 function.You cant use it.
you may need to use DOM XML (PHP 4) Functions

Resources