How to create identifier_hash in typo3's sys_file? - typo3

I want to import some files in Typo3 system using external php Script. How do I create hash field value like identifier_hash folder_hash sha1 for sys_file table?
If I leave these fields empty there is error:
Attempt to modify record '3094' (sys_file_reference:3094) without permission. Or non-existing page.

Probably the best way to do this is to call TYPO3 API,
therefore you have to place somewhere in fileadmin/ and then call
TYPO3\CMS\Core\Resource\getFileObjectByStorageAndIdentifier($storageUid,
$fileIdentifier);
The hashIdentifier function in TYPO3 source utilizes the standard php-sha1 function, just in case you do not want to utilize the TYPO3-API.

$file = array(
'folder' => 'images',
'identifier' => 'images/foobar.jpg'
);
$identifierHash = sha1($file['identifier']);
$folderHash = sha1($file['folder']);
$sha1 = sha1_file($file['identifier']);

Related

Upload files to moodle under a selected course

I have created a particular course using the moodle rest api and i would like to add a files into that particular course. The course may take the week/topic form. I need to add the uploaded file under a selected topic/week how can i achieve that? .I used core_files_upload to upload files but how can i add it to a selected course?
Array
(
[contextid] => int
[component] => string
[filearea] => string
[itemid] => int
[filepath] => string
[filename] => string
[url] => string
)
In order to make a file appear in a course, you would need to create an instance of the 'mod_resource' activity in the course and then attach the relevant file to that resource.
I don't believe there is currently any webservice for creating activities within a course (https://tracker.moodle.org/browse/MDL-40779 appears to still be incomplete).
The best you can do at the moment would be to create a custom Moodle plugin (probably a local plugin) and then implement your own webservice in order to add this functionality.

Trying to add a logic hook to suiteCRM when creating or updating a task

This is my first try into coding for sugarCRM / suiteCRM.
I should say I've been coding for Wordpress for nearly 10 years now, but I'm completely lost now I'm starting to dig into suiteCRM.
I've read that you can add a logic hook to modify the data after saving it to the database, but I don't know where to start...
Imagine I create a task for today, july 7th, related to a client I use to visit every 2 months, so there's a field in Accounts named "Visiting frequency". I'd like to add a future date (july 7th + 60 days = september 7th aprox) into the task's "Future Visiting Date" field, so I can use it to create that particular future task via Workflow.
What I'm trying to do is to calculate a field in tasks (Future visiting date), that equals to the amount of days on the accounts module's field (Visiting frequency) added to the task's own Date field.
I've been able to make it work, using the following layout:
Inside \custom\modules\Tasks\logic_hooks.php
<?php
$hook_version = 1;
$hook_array['before_save'] = Array();
$hook_array['before_save'][] = Array(
1, //Processing index. For sorting the array.
'future_task_date_on_task_creation', //Label. A string value to identify the hook.
'custom/modules/Tasks/future_visit_date.php', //The PHP file where your class is located.
'before_save_class', //The class the method is in.
'future_visit_date' //The method to call.
);
?>
Inside \custom\modules\Tasks\future_visit_date.php
<?php
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class before_save_class {
function future_visit_date($bean, $event, $arguments) {
$bean->rhun_fecha_sig_c = date("Y-m-d H:i:s", $date);
}
}
?>
With this setup, the Future Visiting Date gets filled with the calculated date.
I've also read that this setup is not advised, and that I should use the Extension Framework and put the first file in this path:
/custom/Extension/modules/Tasks/Ext/LogicHooks/<file>.php
But I can't make it work.
Do I have to create the LogicHooks folder if it's not there?
Which filename should I assign to this file?
Do I have to change something else inside the code?
Yes, create the LogicHooks directory if it doesn't exist. The PHP file can be called anything you like.
/custom/Extension/modules/Tasks/Ext/LogicHooks/MyLogicHookFile.php
Define your logic hooks in this file as before.
<?php
$hook_version = 1;
$hook_array['before_save'] = Array();
$hook_array['before_save'][] = Array(
1, //Processing index. For sorting the array.
'future_task_date_on_task_creation', //Label. A string value to identify the hook.
'custom/modules/Tasks/future_visit_date.php', //The PHP file where your class is located.
'before_save_class', //The class the method is in.
'future_visit_date' //The method to call.
);
Then run a repair and rebuild from the Admin panel.
The main advantage to using the Extension framework is that it allows multiple developers to add components to a Sugar instance without worrying about overwriting existing code.
More info can be found about it in the Developer Guide

TYPO3 new record appearing on wrong location in Backend List

I'm developing a new extension using ExtBase in TYPO3 (4.7) for a client.
I have however the strangest problem. In the back-end, my possible, new record types are - as usual - listed in the Insert new record Backend List. Usually each of these record-types are preceded by the module name (actually they are grouped right after the module name).. However, in my case, 1 or 2 of the record-types of any other extension appear within my extension's list as well.. I've been trying to figure out pretty much all that I can, I even copied the extension over to an entirely different TYPO3 installation, but the same problem persists..
If of any extension some records appear just below my extension's title, and I delete that particular extension, just some other record-types appear of another extension.
What's going on here??
Short & late answer:
i guess you have defined the title of your models in two different ways or with a non-existent languagefile in your ext_tables.php. Something like this:
Model1:
$TCA['tx_aaext_domain_model_one'] = array(
'ctrl' => array(
'title' => 'LLL:EXT:bn_news/Resources/Private/Language/locallang_db.xml:tx_bnnews_domain_model_categories',
Model2:
$TCA['tx_aaext_domain_model_two'] = array(
'ctrl' => array(
'title' => 'Static Title',
and/or your extension-name has an underscore like aa_extension, then this error can happen.
Make sure that both title-definitions are dynamic and begin with "LLL:EXT:" and point to an existing translation. Everything should be fine now.
Long answer will be to long :)

How to use form validation with the file uploader to make sure a file is uploaded

Can anyone suggest how using the form validation rules I can say the following:-
If no file is uploaded - then create a rule to say 'no file uploaded' using the form validator library.
I am using CodeIgniter 2.
For instance - it is simple to validate on a text input field using the following, but I cannot understand how this is done with upload (that uses the $_FILES array rather than $_POST)
eg.
$this->form_validation->set_rules('title', 'Title', 'required'); // input field named 'title' is required
CodeIgniter's File Uploading class handles its own validation - no need to use the Form Validation class.
Per the documentation,
$this->upload->display_errors()
Retrieves any error messages if the do_upload() function returned
false. The function does not echo automatically, it returns the data
so you can assign it however you need.
In your example above, if the file input is left empty, $this->upload->display_errors() will return the following:
You did not select a file to upload.
So, set your preferences (see the "Setting Preferences" section of the documentation for exactly what is available):
// The following are just examples from the documentation...
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
// ... other preferences as necessary
If any of the above fail during the attempted upload, $this->upload->display_errors() will retrieve the appropriate error message. Simply pass it to your view to display the error(s).
Hope that helps.

Zend Framework: Alter .ini-Files

in Zend-Framework, is it possible to save an altered .ini-File?
Because altering the $config-Array is easy, if allowModifications = TRUE in Zend_Config_Ini is enabled.
You can use Zend_Config_Writer to modify your config file
$config = new Zend_Config_Ini('config.ini');
// Modify a value
$config->production->value = 'my_value';
$writer = new Zend_Config_Writer_Ini(array('config' => $config,
'filename' => 'config.ini'));
$writer->write();
You may use Zend_Config_Writer_Ini, it works fine, but has one inconvenience. It doesn't matter that you used inheritance in your *.ini file, if you change something in production dimension, the whole dimension will be copied to its descendants, except entries that overrides production. You will also lost all your comments, so be careful using that.