PHP and Protobuf FieldMasks for Google API - php

I found the documentation just fine, but for the life of me I can't figure out how to set up the FieldMasks in PHP to update a CloudSchedulerClient.
The command should be like this:
$client->updateJob($job, $updateMask); but no matter what I set the $updateMask variable to, my code keeps saying Expect Google\Protobuf\FieldMask. If for instance I wanted to update the description of a cron job to "test", 'description' => 'test', how should I go about that?

If you share some code, that would be helpful.
The error suggests that you are not providing the proper type. Your code should look something like this:
use Google\Protobuf\FieldMask;
$updateMask = new FieldMask([
'paths' => ['description']
]);
$client->updateJob($job, $updateMask);

Related

Proper syntax for a POST call to a URL

I am having difficulty with the proper layout for this piece of code I have been talking with another IT support person and we are both at a bit of a loss
I am trying to utilize an API call and I am trying to come up with the proper syntax
I am using a PHP POST call and CURL along with an array of variable names and values for the most part it works
The problem is that a few variable names are not recognized and the other support person thought we needed to change things up a bit
The documentation states there may be a change we need to setup these variable ahead of time
the structure needs to be something like this CDATA block:
<profileFieldValues>
<fieldValue id="_sys_firstname">
<value>Jeff</value>
</fieldValue>
<fieldValue id="_sys_lastname">
<value>Johnson</value>
</fieldValue>
</profileFieldValues>
WE are using a structure like this
$fields = array(
'restype' => '2',
'username' => 'abc123',
...,
)
So what would the profileFieldValues block of code be written to work in the $fields array?
We were trying something like this but it was not correct
'profileFieldValues'=>"fieldValue id[]=>('_sys_firstname=>'value'=>'Charlie','_sys_lastname=>'value'=>'Brown')",
we received an error with this:
The user profile field elements are not properly formatted

Yii2 show image in backend from frontend - settting alias

In my project I used an image cropper widget. I setup the widget, that it save in frontend/web/upload. But in backend I save the images to frontend too.
This is working perfect. Then i want to show the image on the backend, if its exist. And i want to reach the frontend.
Thats why i want to set my own aliases in params-local.php file.
But I using vhosts to my webpages and I want to set Aliases to them.
In Yii2 documentation i found an article from aliases, but it wont help me. I mean i tried to use but it wont work.
I tried this:
return [
'aliases' => [
'#front' => 'http://front.mypage.dev',
'#back' => 'http://back.mypage.dev',
],
];
And I also tried this aswell:
Yii::setAlias('#front', 'http://front.mypage.dev');
Yii::setAlias('#back', 'http://back.mypage.dev');
But when i try to echo Yii::getAlias('#front'); it sais
Invalid Parameter – yii\base\InvalidParamException
Invalid path alias: #front
Maybe someone has a solution for this?
Thanks a lot.
Add in backend/config/params.php like:
return [
'front' => 'http://front.mypage.dev',
'back' => 'http://back.mypage.dev',
];
and use it from:
Yii::$app->params['front']
Yii::$app->params['back']
Let me know your thought.
Try this:
Yii::setAlias('#front', 'http://front.mypage.dev');
Yii::setAlias('#back', 'http://back.mypage.dev');
echo Yii::getAlias('#front');
echo Yii::getAlias('#back');
echo Yii::getAlias('#frontend/path/to/file');
echo Yii::getAlias('#backend/path/to/file');
Yii2 Playground
setting-aliases-in-yii2-within-the-app-config-file

jquery gantt plugin

Situation
I'm using a jQuery gantt plugin from here and integrating it with a PHP site I have. In terms of setting up the demo there are no problems; however when I try to feed the plugin some of my own data, it will throw up the following error:
TypeError: e is undefined
Now, I believe the above error is thrown due to the JSON object being unfamiliar to the plugin but, I just can't seem to package it correctly.
My JSON Data
Demo JSON Data
Now, you can see other than a few differences, I am pretty close to the mark. Up next is the PHP code I use to generate this.
$aryOutput = array('source' => array());
if($aryTasks) {
foreach($aryTasks as $aryTask) {
$aryOutput['source'][] = array(
'name' => $aryTask['task_stage'],
'desc' => $aryTask['task_title'],
'values' => array(array(
'to' => '/Date('.time($aryTask['task_projected_end_timestamp']).')',
'from' => '/Date('.time($aryTask['task_projected_start_timestamp']).')',
'desc' => $aryTask['task_description'],
'label' => $aryTask['task_description']
))
);
}
}
$strJSON = json_encode($aryOutput, JSON_UNESCAPED_SLASHES);
Please can anyone offer some pearls of wisdom to resolve this matter. On a side note, from another question, I saw that the class has to be gantt. This is not a problem, I can get the plugin working with a different data set.
Thank you
Edit
I noticed a small difference with the date field having an extra slash on it. After editing the code to add it, the error still occurs
Check the complete delivered JSON is structure as needs be. In the above example, it is likely this is the output:
source : { source : { ... } }
This causes confusion with the plugin as it is unexpected data.

SugarCRM - How to set the default homepage for all users

I am using SugarCRM Version 5.2.0k (Build 5837). I would like to be able to set a default home page (with dashlets I've created myself) that will be the same for all users, can anyone advice on best way to do this?
Thanks in advance for your help
I'd like to know how to do this too... see here for some ideas, but it's clear that it's not a supported feature.
I wonder if you can write a module that installs a hook for post user creation (assuming that this hook is provided) and then populate the appropriate part of the user preferences table when the hook is invoked. Of course, your module will probably break with each upgrade of SurgarCRM, so this might be more trouble than it i worth.
Edit:
I had a look at the Dash Manager module that is referenced in the thread I linked to above. It's approach is to copy the preferences of the admin user to all other users when the administrator clicks a link in the admin page. So, the admin user is used as a sort of template for other users. Rudimentary solution, but not a bad start - using a template user and treating the preferences (as stored in the DB table) as opaque seems like the way to go.
It's quite easy to do it.
I have done it in SugarCRM 6.5.23.
Here I have mentioned steps to do it:
Just copy sugarcrm_root/modules/Home/index.php and paste it in SugarCRM_root/custom/modules/Home/index.php.
Now you can customize it's behavior as you want.
You can remove default dashlets and add your own dashlets by creating one file at SugarCRM_root/custom/modules/Home/dashlets.php and add this code in it:
<?php
unset($defaultDashlets);
$defaultDashlets = array(
'CustomDashlet' => 'ModuleName',
'UpcomingAppointmentsDashlet' => 'Meetings', //Example
);
Once you do this thing still you have 3 dashlets left in your hook code you can remove it if it's needed code for that hook is like this:
$dashlets[create_guid()] = array(
'className' => 'iFrameDashlet',
'module' => 'Home',
'forceColumn' => 0,
'fileLocation' => $dashletsFiles['iFrameDashlet']['file'],
'options' => array('titleLabel' => 'LBL_DASHLET_DISCOVER_SUGAR_PRO',
'url' => '...',
'height' => 315,
));
Hope this will help you. :)

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