function _calendar_systems_patches_pm_insert in Calendar Systems 6.2
Internal helper to create patch records for the lazy patch_manager project.
Saves a "patch" typed node as per required by patch_manager.module once the Calendar Systems gets installed.
@todo
- Watch for duplicate patch introductions!
Parameters
$patch_filename: The name of the patch file.
$patch_filepath: The relative path to the patch file.
Return value
Boolean value indicating the process result.
See also
http://drupal.org/project/patch_manager
1 call to _calendar_systems_patches_pm_insert()
- calendar_systems_install in ./
calendar_systems.install - Implements hook_install().
File
- ./
calendar_systems.patch.inc, line 163 - A collection of internal helpers around the compatibility patches.
Code
function _calendar_systems_patches_pm_insert($patch_filename = FALSE, $patch_filepath = FALSE) {
if (!module_exists('patch_manager')) {
return;
}
// Get all required and optional patch arrays.
$patches = _calendar_systems_patches();
// Delete the previously introduced patch nodes, if any.
_calendar_systems_patches_pm_delete($patches);
// Create and save a node per patch array.
foreach ($patches as $identifier => $patch) {
// Copy the patch to Drupal's files directory, This way the file
// can be seen by CCK filefield, sorry for the suppression load!
$new_path = file_directory_path() . '/';
if (!@copy($patch['path'] . $patch['name'], $new_path . $patch['name'])) {
// #FAIL.
return FALSE;
}
// Oh, I wish I could automate eth!
// chmod($patch['target'], 0646);
global $user;
// Create and save the patch file.
$file = (object) array(
'file' => 1,
'uid' => $user->uid,
'timestamp' => time(),
'filename' => $patch['name'],
'filesource' => $patch['name'],
'filemime' => file_get_mimetype($patch['name']),
'filepath' => $new_path . $patch['name'],
'filesize' => filesize($new_path . $patch['name']),
'status' => FILE_STATUS_PERMANENT,
);
// Oh, missing D7 file_save().
drupal_write_record('files', $file);
// Retrive the fid of the inserted file to be used in the "patch" typed node.
$file->fid = db_result(db_query("SELECT fid FROM {files} WHERE filepath = '%s'", $file->filepath));
// Build the patch node.
$node = new stdClass();
$node->type = 'patch';
$node->language = 'en';
$node->uid = $user->uid;
$node->title = $patch['title'];
$node->body = $patch['description'];
// CCK module field:
$node->field_module[0]['value'] = $patch['target module'];
// CCK issue number field:
if (!is_null($patch['issue']) && is_numeric($patch['issue'])) {
$node->field_drupal_issue[0]['value'] = $patch['issue'];
}
// Attach the patch file to the node.
$node->field_patch[0] = array(
'list' => 1,
'fid' => $file->fid,
'title' => $file->filename,
'filename' => $file->filename,
'filepath' => $file->filepath,
'filesize' => $file->filesize,
'mimetype' => $file->filemime,
);
// Save the patch node.
content_presave($node);
node_save($node);
content_insert($node);
}
// Yo Happy?
return TRUE;
}