Expression Engine SimpleXmlIterator broken - php

this is my first question, which I can't figure out how to make relevant to other people as per the guidelines. I suppose just a question at the end as to whether a noob should ever attempt to meddle with code they don't fully understand.
My site depends on an xml database generated elsewhere which is spliced into site-specific format, set up by the original developer. The system generating the database changed a tag from "contact" to "person", breaking the data formula for the splicing. (Grr.)
I thought I had fixed it, because I changed the tag in the receiving file, but the splicer has just stopped completely. (Basically, I don’t really know enough about the site/coding to have attempted to make these changes. But I thought I could get away with it!)
This is what I understand happens:
1. every night we send an xml file into folder
2. a php file reformats the raw xml with SimpleXmlIterator.
3. that sends the reformatted file to a staging.sql file.
4. that sends it to the right place for the site to load it nightly.
Step 4 is still happening, but the site is using the same data over and over. The new data is just not making it through step 2 and 3.
This is what I did (I just commented out the original code. I'm "SOC"):
$authors = array();
foreach ($author_array as $arr) {
$bio = ($arr['copy_biography']) ? nl2br(htmlspecialchars($arr['copy_biography'], ENT_QUOTES)) : '';
// SOC changed $author_title = $arr['contact_first_name'] .' '. $arr['contact_surname'];
$author_title = $arr['person_first_name'] .' '. $arr['person_surname'];
$authors[] = array(
'title' => $author_title,
'author_id' => $arr['id'],
// SOC changed from this to the below 'fname' => $arr['contact_first_name'],
'fname' => $arr['person_first_name'],
// SOC changed from this to the below 'lname' => $arr['contact_surname'],
'lname' => $arr['person_surname'],
// SOC ditto 'website' => $arr['contact_web_page'],
'website' => $arr['person_web_page'],
'bio' => $bio,
// SOC ditto 'twitter' => $arr['contact_fax']
'twitter' => $arr['person_fax']
);
}
$authors = generate_valid_xml_from_array($authors);
$authors_xml = '/var/www/hotkeybooks/biblio/authors_import.xml';
$authorfile = fopen($authors_xml,'w') or die("can't open file");
fwrite($authorfile,$authors);
fclose($authorfile);
//make the files readable
exec('chmod 444 /var/www/hotkeybooks/biblio/*.xml');
I also changed “contact” to “person” the staging.sql and the staging.tgz.
-- ----------------------------
-- Records of `exp_dd_doc_sections`
-- ----------------------------
BEGIN;
INSERT INTO `exp_dd_doc_sections` VALUES (…….<td>contact_first_name, contact_surname</td>\n <td>Text Input</td>\n <td>Would enter author full name, this field would only be used for admin purposes.</td>\n <td>y</td>\n </tr>\n <tr>\n <td>Author Biblio ID</td>\n <td>author_biblio_id</td>\n <td>id</td>\n <td>Text Input</td>\n <td>Used for relationship building and reference only</td>\n <td></td>\n </tr>\n <tr>\n <td>Author First Name</td>\n <td>author_fname</td>\n <td>contact_first_name</td>\n <td>Text Input</td>\n <td></td>\n <td></td>\n </tr>\n <tr>\n <td>Author Last Name</td>\n <td>author_lname</td>\n <td>contact_surname</td>\n <td>Text Input</td>\n <td></td>\n <td></td>\n </tr>\n ………)
Does anyone know which bit of what I did broke the system, and what I can do to restore it?
I have tried overwriting my changes with the original files, but that hasn’t helped.
Any guidance would be greatly appreciated.

Sounds like you need some basic troubleshooting.
Perhaps your parsing is working correctly but the transfer between the various locations is failing due to file permissions or something.
Working backwards:
Can you confirm that the file that is transferred in step 4 is a new file? Does it have the expected modified date? Does it have the expected data?
Can you confirm that the file in step 3 staging.sql is a new file with the expected modified date? Does it have the expected data?
Can you confirm that the file created in step 2 is a new file with the expected date and data?
Do you seeing anything in your error log to suggest that anything in the script has failed?

Related

How to change the values of Grading method dropdown in Moodle 2.6

Thanks in advance,
I have some customer requirements to change Moodle grade into score(literally the keyword).
I've tried to find the Grading method dropdown (present in "moodle/course/modedit.php") in database and the also in the code but unfortunately did't got the solution.
below mentioned is my findings of some presets in moodle\mod\quiz\lib.php
/**##+
* Options determining how the grades from individual attempts are
combined to give
* the overall grade for a user
*/
define('QUIZ_GRADEHIGHEST', '1');
define('QUIZ_GRADEAVERAGE', '2');
define('QUIZ_ATTEMPTFIRST', '3');
define('QUIZ_ATTEMPTLAST', '4');
/**##-*/
and in moodle\mod\quiz\mod_form.php
$mform->addElement('select', 'grademethod', get_string('grademethod',
'quiz'),quiz_get_grading_options());
need to know where it comes from?
function quiz_get_grading_options() {
/*
return array(
QUIZ_GRADEHIGHEST => get_string('gradehighest', 'quiz'),
QUIZ_GRADEAVERAGE => get_string('gradeaverage', 'quiz'),
QUIZ_ATTEMPTFIRST => get_string('attemptfirst', 'quiz'),
QUIZ_ATTEMPTLAST => get_string('attemptlast', 'quiz')
);
*/
// Commented and added by sherin on 07/05/2019
return array('Highest score','Average score','First attempt','Last
attempt');
}
I've edited the existing return array in the above mentioned function(present in mod\quiz\locallib.php) and it finally worked, do some one know where the actual data is comes from?
QUIZ_GRADEHIGHEST => get_string('gradehighest', 'quiz')
Hope you guys understand the problem, please help.
Sherin... If I understand your question correctly, I think you need to change the language file that is in the 'lang' directory.
In the path /mod/quiz/lang/ (/en/, /es/,... and so for each language you have installed) there is a php file with all the words that are displayed. If you do not find the files in that route, are probably located in the moodledata.

Changing the description of a MP3 file?

I am currently using simple_html_dom to parse some MP3 files from another website, and store them onto my own server. However I've noticed that some of them contain a tag which indicates the location they originated from within the comment portion of the ID3 properties.
I need to make this website, say my own websites name. However, the only solution that I've found to doing this with PHP is beyond complicated using something called GETID3.php You can view the github link by clicking the name.
I don't really understand the documentation can someone help me find an easier way of doing this please?
Here's the part of my code that matters, I guess.
$mp3title = ''.$thetitle.' - Oursite.com';
file_put_contents($DPATH.'/temp/'.$mp3title.'.mp3',file_get_contents($filepath));
$file = $DPATH.'/temp/'.$mp3title.'.mp3';
Provided you're not interested in also updating the image of the file, you can look into just using something simple like the default php function id3_set_tag however for more complex usages like updating the artwork then you're going to have to use the library you mentioned before.
$data = array(
"title" => "Re:Start",
"artist" => "Re:\Legion",
"comment" => "YourWebsiteName.com"
);
$result = id3_set_tag($DPATH.'/temp/'.$mp3title.'.mp3', $data, ID3_V1_0 );
if ($result === true) {
echo "Tag successfully updated\n";
}

Trying to add records to a table with MYSQL and php, with a forced unique identifier

I am trying to modify a script that was developed to import article records from a Joomla (1.5.x) database into a Wordpress 3.2.1 table for posts. It is a script that migrates content from Joomla to Wordpress.
The issue I had with the script is that it did not maintain the unique identifier ('id' in Joomla, and 'ID' in Wordpress). Based on my understanding, this makes it a lot more complicated (much more work) to deal with redirecting all the Joomla permalinks over to the new (and obviously different) Wordpress permalinks. If the ID was the same in WP as it was in Joomla then some basic rewrite rules in htaccess would be enough to perform the redirections.
So I want to see if I can modify the code to force the ID rather than it being generated in consecutive order as records are inserted into the table.
The script I am modifying is available here: http://wordpress.org/extend/plugins/joomla-to-wordpress-migrator/
The file in question is called: joomla2wp-mig.php
The array is being created at around line 1049 and 1081.
At line 1049 it is:
$wp_posts[] = array(
'ID' => $R->id, //I ADDED THIS IN
'post_author' => $user_id,
'post_category' => array($wp_cat_id),
'post_content' => $post_content,
'post_date' => $R->created,
'post_date_gmt' => $R->created,
'post_modified' => $R->modified,
'post_modified_gmt' => $R->modified,
'post_title' => $R->title,
'post_status' => 'publish',
'comment_status' => 'open',
'ping_status' => 'open',
'post_name' => $R->alias,
'tags_input' => $R->metakey,
'post_type' => 'post'
);
And at line 1081 it is:
$array = array(
"ID" => $item['ID'], //I ADDED THIS IN
"post_author" => $user_id,
"post_parent" => intval($wp_cat_id),
"post_content" => $item['post_content'],
"post_date" => $item['post_date'],
"post_date_gmt" => $item['post_date_gmt'],
"post_modified" => $item['post_modified'],
"post_modified_gmt" => $item['post_modified_gmt'],
"post_title" => $item['post_title'],
"post_status" => $item['post_status'],
"comment_status" => $item['comment_status'],
"ping_status" => $item['ping_status'],
"post_name" => $item['post_name'],
"post_type" => $item['post_type']
);
I have commented the ID line which I have added into the top of each of these bits of array code.
The INSERT command is being implimented around line 1097
The INSERT command is put together like this:
$insert_sql = "INSERT INTO " . $j2wp_wp_tb_prefix . "posts" . " set ";
$inserted = 0;
foreach ($array as $k => $v)
{
if($k AND $v)
{
if($inserted > 0)
$insert_sql .= ",";
$insert_sql .= " ".$k." = '".mysql_escape_string(str_replace("`","",$v))."'";
++$inserted;
}
}
$sql_query[] = $insert_sql;
}
It uses the MYSQL function INSERT INTO... SET (as opposed to INSERT INTO... VALUE)
The challenge I have is this:
The array did not include the ID, so I have added this in.
Having made this change, when I run the script it will appear (at the Wordpress UI end) to run fine, but no records are inserted, even though it says it was successful.
I found I could get around that issue by setting up a fresh wp_posts table with X number of blank records. Let's say I am importing 100 articles, then I would put 100 records into the table, and they would have ID 1 to 100. When I run my modified code it will happily update and populate these existing records. What I don't understand is why it will not create new records when I force the unique identifier (ID) to what I want it as.
I am wondering if I need to use the INSERT INTO... VALUE command instead of INSERT INTO... SET
I was going to test that out, but to be honest I am not a programmer and am just winging it as I go along. So I had not idea how to rewrite the PHP in order to impliment the structure required for the VALUE command in place of SET.
Any help or suggestions would be greatly appreciate.
I gather I have to rewrite the last bit of code I provded above.
There is some discussion on this matter at the wordpress support forums. One user (spiff06) very kindly helped troubleshoot the issue with me. We came unstuck around getting the code to insert new records with a forced identifier, and I went with what we referred to as the "messy" option (which is the method I mentioned above... setting up a table with the required number of blank records).
Even though I've used that "messy" method for my own site, it is my wish to make this process work cleanly for other users who are on Joomla 1.5.x and are switching to WP instead of upgrading to a newer Joomla release (which is a big process, so many are just jumping ot WP, like me).
With much thanks...
Jonathan
You can try the following:
Change the structure of the imported mysql table (post#wordpress). Change the id field so it is not anymore an autoincrement field. Let it being just an integer field.
Import the values. This way you can put any values in the field ID without limitations at all.
After the importation change again the structure of the table to set the ID field to be again an autoincrement field.
I never found a truly automated / scripted way of doing this. I ended up doing a workaround:
For now I've imported all my posts the "messy" way, by prepopulating the table.
THE WORKSROUND METHOD
Prepopulate the wp_posts table in the WP database with as many records as you require (look in Joomla to see how many records you have). I had 398, so I added 398 records to wp_posts.
HOW? I did it by exporting the emtpy wp_posts table to a .csv file. I then opened this in Excel (Numbers, or OpenOffice would also do). In the spreadsheet application it was easy to autofill 1 to 398 in the ID column.
I then reimported that .csv file into wp_posts. This gave me a wp_posts with 398 record rows with 1 to 398 in the ID field.
I then ran version 1.5.4 of Mambo/Joomla to WordPress migrator, which can be installed from within WordPress.
End result?
All posts have the same ID as the original Joomla articles.

Howto: Drupal File Upload Form

I'm having difficulty figuring out how to write a module with a form that uploads files, in Drupal 6. Can anyone explain this, or point me to a good example/documentation discussing it?
EDIT:
Here is entirely what I am trying to do:
User uploads a .csv
Module reads the first line of the file to get fields
User matches csv fields with db fields
Each csv line is saved as a node (preview it first)
So far, I can do 1, 2, and 4 successfully. But it's unclear exactly how the steps should interact with each other ($form_state['redirect']? how should that be used?), and what the best practices are. And for 3, should I save that as session data?
How do I pass the file data between the various steps?
I know that node_import exists, but it's never worked for me, and my bug requests go ignored.
2nd EDIT: I used this at the start and end of every page that needed to deal with the file:
$file = unserialize($_SESSION['file']);
//alter $file object
$_SESSION['file'] = serialize(file);
I'm not sure it it's best practices, but it's been working.
This is not too difficult, you can see some info here. An example of a form with only a file upload.
function myform_form($form_state) {
$form = array('#attributes' => array('enctype' => 'multipart/form-data'));
$form['file'] = array(
'#type' => 'file',
'#title' => t('Upload video'),
'#size' => 48,
'#description' => t('Pick a video file to upload.'),
);
return $form;
}
EDIT:
Now to save the file use the file_save_upload function:
function myform_form_submit($form, $form_state) {
$validators = array();
$file = file_save_upload('file', $validators, 'path');
file_set_status($file, FILE_STATUS_PERMANENT);
}
2nd EDIT:
There's a lot of questions and ways to do the things you described. I wont go to much into the actual code of how to handle a csv file. What I would suggest is that you use the file id to keep track of the file. That would enable you to make urls that take a fid and use that to load the file you want to work on.
To get from your form to the next step, you can use the #redirect form property to get your users to the next step. From there is really depends how you do things, what you'll need to do.

Drupal - Automate a Content Form Submission

I would like to programatically (using php) fill out an existing drupal form to create a content type that is included in a contributed module.
Details: The module is SimpleFeed and the content type is Feed. I would like to call the module's functions to accomplish this. The method I am interested in is hook_insert which appears to require vid and nid which I am unsure what these are.
Any help is appreciated.
can you provide a bit more information (which modules?). generally, i'd probably suggest calling the modules functions to create the content type, instead of trying to pass it through a form programatically. this way you don't have to worry about implementation, and can trust that if the module works, it'll work for your script too :)
of course this does tie your module to theirs, so any changes in their functions could affect yours. (but then again, you run that risk if they update their database structure too)
ex.
// your file.php
function mymodule_do_stuff() {
cck_create_field('something'); // as an example, i doubt this
// is a real CCK function :)
}
edit: vid and nid are node ID's, vid is the revision id, and nid is the primary key of a particular node. because this is an actual node, you may have to do two operations.
programatically create a node
you'll have to reference the database for all the exact fields (tables node and node_revisions), but this should get you a basic working node:
$node = (object) array(
'nid' => '', // empty nid will force a new node to be created
'vid' => '',
'type' => 'simplefeed'. // or whatever this node is actually called
'title' => 'title of node',
'uid' => 1, // your user id
'status' => 1, // make it active
'body' => 'actual content',
'format' => 1,
// these next 3 fields are the simplefeed ones
'url' => 'simplefeed url',
'expires' => 'whatever value',
'refresh' => 'ditto',
);
node_save($node);
now i think it should automatically call simplefeed's hook_insert() at this point. if not, then go on to 2. but i'd check to see if it worked out already.
call it yourself!
simplefeed_insert($node);
edit2: drupal_execute() isn't a bad idea either, as you can get back some validation, but this way you don't have to deal with the forms API if you're not comfortable with it. i'm pretty sure node_save() invokes all hooks anyhow, so you should really only have to do step 1 under this method.
The drupal api provides drupal_execute() to do exactly this. I would suggest you avoid calling the functions directly to create the node (unless there is a performance reason). By using drupal_execute() all the proper hooks in other modules will be called and your code is far more likely to continue to work through future versions of drupal.
Note that a classic bug in using this method is not first calling something like
module_load_include('inc', 'node', 'node.pages')
which will load the code for your node creation form.
Calling node_save directly is generally considered deprecated and could leave you with broken code in future versions of drupal.
There is a nice example at this lullabot post

Categories