Moodle - Invalid course module ID - moodle

I am adding a folder module to a Moodle course using the API:
folder_add_instance($data, null);
I am getting the error below when running the script using CMD:
!!! Invalid course module ID !!!
I looked into the folder_add_instance() function in the library, the error is occurring when trying to get the context:
$context = context_module::instance($cmid)//$cmid = 8
i looked into the mdl_context table in Moodle database but couldn't understand the values and their relation to the error i am getting.
Will deleting the mdl_context values from the database will help? or i am missing something here?
Note that the script was working fine, until i deleted all the courses i had on Moodle using the web interface.(i deleted the category containing all the courses).

To programmatically create a module in Moodle you should use function add_moduleinfo().
Look at the example in the folder generator:
https://github.com/moodle/moodle/blob/master/mod/forum/tests/generator/lib.php#L67
Will be something like:
require_once($CFG->dirroot.'/course/modlib.php');
$foldername = 'YOUR NAME HERE';
$courseid = 12345;
$sectionnum = 0;
$course = get_course($courseid);
$moduleid = $DB->get_field('modules', 'id', array('name' => 'folder'));
$data = (object)array(
'name' => $foldername,
'intro' => '',
'display' => FOLDER_DISPLAY_PAGE,
'revision' => 1,
'showexpanded' => 1,
'files' => file_get_unused_draft_itemid(),
'visible' => 1,
'modulename' => 'folder',
'module' => $moduleid,
'section' => $sectionnum,
'introformat' => FORMAT_HTML,
'cmidnumber' => '',
'groupmode' => NOGROUPS,
'groupingid' => 0,
'availability' => null,
'completion' => 0,
'completionview' => 0,
'completionexpected' => 0,
'conditiongradegroup' => array(),
'conditionfieldgroup' => array(),
'conditioncompletiongroup' => array()
);
return add_moduleinfo($data, $course, $mform = null);

Invalid course module ID . That means moodle can find a course module record, but the cm doesn't actually exist in the course object when fetching all the course data.
What you can do to fix it is add the broken module back into a section of this course. It might be in a section that exists, then you also need to add the cmid to the sequence field. (Just add this cmid on the end of the existing sequence).
update mdl_course_modules set section=<existingsection> where id=cmid;
update mdl_course_sections set sequence='XX,YY,ZZ,cmid' where id =<existingsection>;
Then after you purge caches, you should now be able to view the module again, eg. for an assignment:
https://moodle.com/mod/assign/view.php?id=cmid

Related

First/Last record is not coming with data in cakephp+mongo

I m using the mongodb plugin
ichikaway/cakephp-mongodb
And cakephp 2.6.1
The data in post collection
link to image
And in cakephp it is showing me like
link to image
Cakephp controller side code:
$params = array(
'fields' => array('title', 'body', 'hoge'),
//'fields' => array('Post.title', ),
//'conditions' => array('title' => 'hehe'),
//'conditions' => array('hoge' => array('$gt' => '10', '$lt' => '34')),
//'order' => array('title' => 1, 'body' => 1),
'order' => array('_id' => "DESC"),
'limit' => 35,
'page' => 1,
);
$results = $this->Post->find('all', $params);
I want to pull each and every data from mongodb but this plugin is not providing me the last data.
I have checked the count that's correct.
Am I correct in assuming that this error only appeared after upgrading the PHP driver to 1.6.0? The CakePHP module uses hasNext() and getNext() in MongodbSource::read(), which will be affected by a bug (PHP-1382) introduced in 1.6.0. A fix has already been merged and should be released as 1.6.1 on 2015-02-05 (tomorrow).
For additional context, see a previous answer on the subject: https://stackoverflow.com/a/28304142/162228
In MongodbSource.php file I have made just simple change
in read function
There was a code
public function read(Model $Model, $query = array(), $recursive = null) {
........
while ($return->hasNext()) {
$mongodata = $return->getNext();
Changed it to
public function read(Model $Model, $query = array(), $recursive = null) {
........
foreach ($return as $data) {
$mongodata = $data;
And yurekaaaa,its working fine.

Using Forge to Insert into database but not getting an insert ID

I'm new to Fuel...
got my script inserting a record using the following code:
$address = Model_Address::forge(array(
'street1' => $step1_data['street1'],
'street2' => $step1_data['street2'],
'suburb' => $step1_data['street2'],
'city' => $step1_data['city'],
'region' => $step1_data['region'],
'country' => $step1_data['country'],
'postcode' => $step1_data['postcode'],
));
$address->save();
I think I should be able to get the insert id via $address->id but it's empty.
I'm not sure what I'm doing wrong?
We are using pg_swl not sure if that makes any difference.

Symfony2 - Functional Testing File uploads with dynamically created fields

I'm fighting with functional testing of files uploading.
I will try to simplify my situation. Let's say I have
a company entity, which has 3 fields.
Company {
protected name;
protected tags;
protected images;
}
Images is array of CompanyImage entities, which serve for
storing image files and tags contains array of Tag entities,
which can be m:n connected with companies.
In the form I use jquery, for adding tags and images dynamically.
(you can create images and add them to the company similar to the
collection type symfony tutorial)
Because images and tag arrays are created with jquery, I cannot
simply use something like the turorial line below in the functional test of the company form.
$form['images'][0]->upload('/path/to/image.jpg');
For the setting
of the form values I use simple a little trick described by sstok here
(https://github.com/symfony/symfony/issues/4124)
public function testCompanyCreation() {
...
//option1
$image = new UploadedFile(
'/path/to/image.jpg',
'image.jpg',
'image/jpeg',
123
);
//or option2
//$image = array('tmp_name' => '/path/to/image.jpg', 'name' => 'image.jpg', 'type' => 'image/jpeg', 'size' => 300, 'error' => UPLOAD_ERR_OK);
$companyFormNode = $companyCrawler->selectButton('Create');
$companyForm = $companyFormNode->form();
$values = array(
'company' => array(
'_token' => $companyForm['company[_token]']->getValue(),
'name' => 'test company',
'tags' => array('1'),
'images' => array('0' => (array('file' =>$image))),
),
);
$companySubmitCrawler = $client->request($companyForm->getMethod(), $companyForm->getUri(), $values, $companyForm->getPhpFiles());
}
this works perfectly until I try to upload the image file.
With the option1 I get following exception
Exception: Serialization of 'Symfony\Component\HttpFoundation\File\UploadedFile' is not allowed
when I use option2 I get this
Argument 1 passed to Acme\myBundle\Entity\CompanyImage::setFile() must be an instance of Symfony\Component\HttpFoundation\File\UploadedFile, array given, called in ...\PropertyAccess\PropertyAccessor.php on line 347 and defined (500 Internal Server Error)
I would also like to point out, that the whole form and uploading of the files works without any problems in the browser. I also tried to make the entities serializable, and it didn't help. Do I have a bug somewhere?
I have figured it out (took couple of hours). Files have to be uploaded in a separate array.
$companyForm = $companyFormNode->form();
$values = array(
'company' => array(
'_token' => $companyForm['company[_token]']->getValue(),
'name' => 'test company',
'tags' => array('1')
),
);
$files = array(
'company' => array('images' => array('0' => (array('file' => $image))))
);
$companySubmitCrawler = $client->request(
$companyForm->getMethod(),
$companyForm->getUri(),
$values,
$files
);

Can someone provide a php sample using nusoap/sugarcrm api to create an acct/lead in sugarcrn?

Can someone provide a sample code chunk of php using the sugarcrm API/nusoap for adding creating an acct. and then linking a lead to the acct?
I've got a sample function that adds a lead, and I can see how to create an acct, but I can't see how to tie a lead to the acct, to simulate the subpanel process in the sugarcrm acct/subpanel process.
thanks
// Create a new Lead, return the SOAP result
function createLead($data)
{
// Parse the data and store it into a name/value list
// which will then pe passed on to Sugar via SOAP
$name_value_list = array();
foreach($data as $key => $value)
array_push($name_value_list, array('name' => $key, 'value' => $value));
// Fire the set_entry call to the Leads module
$result = $this->soap->call('set_entry', array(
'session' => $this->session,
'module_name' => 'Leads',
'name_value_list' => $name_value_list
));
return $result;
}
$result = $sugar->createLead(array(
'lead_source' => 'Web Site',
'lead_source_description' => 'Inquiry form on the website',
'lead_status' => 'New',
'first_name' => $_POST['first_name'],
'last_name' => $_POST['last_name'],
'email1' => $_POST['email'],
'description' => $_POST['message']
));
You need to find the ID for the account and assign that ID to whatever the account_id field name is in the Lead Module. I have run into a couple things like this before and I have found it easier to go straight to the Sugar database. So, write a statement that will return the account is, for example: SELECT id WHERE something_in_the_account_table = something else;
Then you can assign that id in your $result array. I hope it helps. I didn't have any code or documentation in front of me or I would have helped more.

How to fix propect_lists subpanel in accounts, contacts and leads?

There is a description by Robert Lausegger (iscon group) which made it possible to show prospect list in a subpanel in other modules. But since SugarCRM 6.3 this wasn't working anymore.
How to fix this?
The site referenced in the above link was in German, so, courtesy of the author of that site, Robert Laussegger of the iscon group (www.iscongroup.net) in Germany, here is the english language version of the method. I used this on SugarCRM CE v 6.5 running on a LAMP stack with CentOS 6.4 base and it worked fine. Adjust to your install as appropriate.
The example given shows how to add a Target List (called Prospect List internally with SugarCRM) to a Contact DetailView; adjust the settings for Leads, ...
If the directories shown do not exist, create them, being careful to match not only spelling but capitalization. You will be adding 3 files in 3 separate directories.
Remember to set the file permissions and owner/group to allow the server to access the files created.
When finished adding the files and setting the permissions, as a CRM administrator, run:
Admin -> Repair -> Rebuild Relationships (to flush cache)
Admin -> Repair -> Quick Repair and Rebuild
Create the following files in the directories shown:
In /var/www/html//custom/Extension/modules/Contacts/Ext/Language
-Create file en_us.prospectlist_in_contacts_language.php
and into the file put
(the part of the filename " prospectlist_in_contacts_language" can be whatever you want, as long as you use the prefix "en_us." (for US English language) and the suffix ".php")
<?php
$mod_strings['LBL_PROSPECTLISTS_CONTACTS_FROM_PROSPECTLISTS_TITLE'] = 'Target Lists';
?>
In /var/www/html//custom/Extension/modules/Contacts/Ext/Layoutdefs
Create file prospectlist_in_contacts_layoutdef.php
and into the file put
(the part of the filename " prospectlist_in_contacts_layoutdef" can be whatever you want, as long as you use the suffix ".php")
<?php
$layout_defs["Contacts"]["subpanel_setup"]["prospect_list_contacts"] = array (
'order' => 100,
'module' => 'ProspectLists',
'subpanel_name' => 'default',
'sort_order' => 'asc',
'sort_by' => 'id',
'title_key' => 'LBL_PROSPECTLISTS_CONTACTS_FROM_PROSPECTLISTS_TITLE',
'get_subpanel_data' => 'prospect_list_contacts',
'top_buttons' =>
array (
0 =>
array (
'widget_class' => 'SubPanelTopButtonQuickCreate',
),
1 =>
array (
'widget_class' => 'SubPanelTopSelectButton',
'mode' => 'MultiSelect',
),
),
);
?>
In /var/www/html//custom/Extension/modules/Contacts/Ext/Vardefs
Create file prospectlist_in_contacts_vardef.php
and into the file put
(the part of the filename " prospectlist_in_contacts_vardef" can be whatever you want, as long as you use the suffix ".php")
<?php
$dictionary["Contact"]["fields"]["prospect_list_contacts"] = array (
'name' => 'prospect_list_contacts',
'type' => 'link',
'relationship' => 'prospect_list_contacts',
'source' => 'non-db',
'vname' => 'LBL_PROSPECTLISTS_CONTACTS_FROM_PROSPECTLISTS_TITLE',
);
$dictionary["Contact"]["fields"]["prospect_list_name"] = array (
'name' => 'prospect_list_name',
'rname' => 'name',
'id_name' => 'prospect_list_id',
'vname' => 'LBL_PROSPECTLISTS_CONTACTS_FROM_PROSPECTLISTS_TITLE',
'type' => 'relate',
'link' => 'prospect_lists',
'table' => 'prospect_lists',
'isnull' => 'true',
'module' => 'ProspectLists',
'dbType' => 'char',
'len' => '255',
'source' => 'non-db',
);
?>
Reset owner/permissions
Run, as CRM administrator
Admin -> Repair -> Rebuild Relationships (to flush cache)
Admin -> Repair -> Quick Repair and Rebuild
The vardefs have to be changed to:
$dictionary["Lead"]["fields"]["prospect_lists"] = array(
'name' => 'prospect_lists',
and the layoutdefs
'get_subpanel_data' => 'prospect_lists',
This solves the problem.