Get folder with path ONEDRIVE - onedrive

I am using this PHP API and I want to check if folder is created if not then create it. So I am using
function folderExists()
{
return $this->folder = $this->client->fetchObject("me/skydrive/FOLDER_NAME");
}
But I cannot get the path right. Best I can get is this
Uncaught exception 'Exception' with message 'The resource
'd3b7bfe6cdaba4b7' doesn't exist.
But that ID is still not enough, I would need this
folder.d3b7bfe6cdaba4b7.D3B7BFE6CDABA4B7!527
to access it.

I managed to solve it with this
function folderExists()
{
$id = $this->client->fetchRoot();
$folders = $id->fetchObjects();
foreach ($folders as $id => $folder) {
if($folder->getName() === $this->config['FOLDER_NAME'])
return $this->folder = $folder;
}
}

Related

Shopware 6 custom element type image not showing any data on storefront

I have created my component to add some desired config fields in Shopware 6. Everything is working fine but one problem that is image is looking as it is being saved in the administration but is not showing any src or else in dump.
And here is my dump preiew having #data null.
can anyone tell what should I do else here?
I will be very thankful.
There is a guide in the docs that explains exactly what your case is.
You can likely extend the \Shopware\Core\Content\Media\Cms\ImageCmsElementResolver and override the getType function:
public function getType(): string
{
return 'my-component-name';
}
The important part of the default ImageCmsElementResolver is the loading the media information. For that you also need in your CMS element resolver. I explain some parts of the existing ImageCmsElementResolver so you can see which steps you need:
public function collect(CmsSlotEntity $slot, ResolverContext $resolverContext): ?CriteriaCollection
{
// read the configuration, that is defined in the Admin JS. Likely also media for you
$mediaConfig = $slot->getFieldConfig()->get('media');
// if this config is NOT containing useful info
if (
$mediaConfig === null
|| $mediaConfig->isMapped()
|| $mediaConfig->isDefault()
|| $mediaConfig->getValue() === null
) {
// return nothing
return null;
}
// otherwise use the configured value as mediaId to load the media entry from the database
$criteria = new Criteria([$mediaConfig->getStringValue()]);
$criteriaCollection = new CriteriaCollection();
$criteriaCollection->add('media_' . $slot->getUniqueIdentifier(), MediaDefinition::class, $criteria);
// return the criterias to execute later, when all needed entities for the CMS page are fetched
return $criteriaCollection;
}
Now the data is fetched and as next step you need to put it into a variable accessible from the Twig template. For this you write into the same CMS element resolver this:
public function enrich(CmsSlotEntity $slot, ResolverContext $resolverContext, ElementDataCollection $result): void
{
$config = $slot->getFieldConfig();
$image = new ImageStruct();
// this is important for accessing data in Twig
$slot->setData($image);
// read the config again
$mediaConfig = $config->get('media');
// if the configuration looks promising
if ($mediaConfig && $config->isStatic() && $mediaConfig->getValue()) {
$image->setMediaId($config->getStringValue());
// look up the media from the entity loading step
$searchResult = $result->get('media_' . $slot->getUniqueIdentifier());
if (!$searchResult) {
return;
}
/** #var MediaEntity|null $media */
$media = $searchResult->get($config->getValue());
// if we do not have a media, then skip it
if (!$media) {
return;
}
// set the media entity to the slot data we just assigned to the slot
$image->setMedia($media);
}
}
After that you should have more info in the slot variable in Twig to embed a media.

non-invocable member 'File' cannot be used like a method error message- what am I missing?

I have a Blazor Application which had files uploaded to a upload folder on the web server. I am in the process of trying to figure out the code to download an uploaded file in the browser for retrieval and viewing. Right now the code is as below (the download part from code examples on the internet)
public void FileDetailsToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args)
{
string path = null;
string uploads = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "wwwroot\\uploads");
path = uploads + "\\" + SelectedFileName;
if (args.Item.Text == "Delete")
{
//Code for Deleting goes here
//UploadRef.Remove();
if (System.IO.File.Exists(path))
{
System.IO.File.Delete(path);
}
FileDetailsService.FileDetailsDelete(SelectedFileId); //NavigationManager.NavigateTo($"/ServiceRequestNotes/servicerequestnoteadd");
NavigationManager.NavigateTo($"/ServiceRequests/serviceRequestsaddedit2/{Id}", forceLoad: true);
}
else
{
// its a download
IFileProvider provider = new PhysicalFileProvider(uploads);
IFileInfo fileinfo = provider.GetFileInfo(path + SelectedFileName);
var readStream = fileinfo.CreateReadStream();
var mimeType = "application/pdf";
return File(readStream, mimeType, SelectedFileName);
}
}
On the last statement I am a getting the following error message
non-invocable member 'File' cannot be used like a method error message
What am I missing or do I need to change or add to have the output from the readstream render to the browser?
The blazor application is a blazor server app not WASM. It does not make use of API controllers.
Any advice?
This is a void method. You can't return anything at all. Also, if you're trying to instantiate a File object, you'd have to use the new keyword.

YII2 problem with permissions and CAN function

I have a YII2 advanced template application with a function:
public function isVisible()
{
if ($return = \Yii::$app->getUser()->can($this->getWidgetPermission())) {
return true;
} else {
return false;
}
}
This function is not behaving the expected way with a specific permission, if I add the following code to print all user permissions and the involved permission:
public function isVisible()
{
if ($return = \Yii::$app->getUser()->can($this->getWidgetPermission())) {
return true;
} else {
pr($this->getWidgetPermission() ,'NON ALLOWED!');
pr(\Yii::$app->authManager->getPermissionsByUser(\Yii::$app->getUser()->getId()));
return false;
}
}
I get the name of the permission with the first pr() and an array of permissions with the second pr().
What is odd: the array of permissions INCLUDES the first one.
For example:
output of first pr():
backend\modules\m3p2\widgets\icons\WidgetIconProjects
output of second pr():
[
..,
[name] => backend\modules\m3p2\widgets\icons\WidgetIconProjects
..,
]
So IN THEORY:
\Yii::$app->getUser()->can($this->getWidgetPermission()
should return TRUE, but it's not!
Am I missing something obvious here?
BTW: I flushed permissions and nothing changed
Turned out the problem was in the cache.
I don't know why but both:
php yii cache/flush rbacCache and
php yii cache/flush-all
didn't clean the cache at all.
I had to manually delete the Cache files (in my case inside /runtime/rbacCache/rb/)

Custom Sendinblue API available for CodeIgniter?

I am searching for a SendinBlue API for Codeigniter but not found yet.
In the case that the API does not exists yet, is that hard to code it by myself (I already know HTTP requests but I not have any idea about configs)
Or is that possible to use the PHP one ?
Thanks
I have a beautiful solution for this and it works fine for me and I hope it will work for you as well.
I am using API-v3.
What I did is:
Downloaded the API through composer on my local PC.
Created a folder named "sendinblue" on the server (where we have
assets folders) and upload the vendor folder from the downloaded API
inside this folder.
Created a library named "Sendinblue.php" and added all the necessary functions here. Now I can use this library like other libraries.
This is my library structure:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Sendinblue{
public $config;
public $apiInstance;
public function __construct(){
require_once('sendinblue/vendor/autoload.php');
$this->config = SendinBlue\Client\Configuration::getDefaultConfiguration()->setApiKey('api-key', '');
$this->apiInstance = new SendinBlue\Client\Api\ContactsApi(
new GuzzleHttp\Client(),
$this->config
);
}
public function get_contact_info($data){
$identifier = $data['email'];
try {
return $result = $this->apiInstance->getContactInfo($identifier);
} catch (Exception $e) {
return 'Exception when calling ContactsApi->getContactInfo: '.$e->getMessage();
}
}
public function create_contact($data){
$createContact = new \SendinBlue\Client\Model\CreateContact();
$createContact['email'] = $data['email'];
$createContact['listIds'] = [2];
try {
return $result = $this->apiInstance->createContact($createContact);
} catch (Exception $e) {
return $e->getCode();
}
}

Saving data with cakephp won't work

I'm trying to load, edit and save a record with CakePHP 2.0 but I get a generic error during the save method that don't help me to understand where is the problem.
if I try with debug($this->User->invalidFields()); I get an empty array, but I get false from $this->User->save() condition.
Here is the controller action where I get the error:
public function activate ($code = false) {
if (!empty ($code)) {
// if I printr $user I get the right user
$user = $this->User->find('first', array('activation_key' => $code));
if (!empty($user)) {
$this->User->set(array (
'activation_key' => null,
'active' => 1
));
if ($this->User->save()) {
$this->render('activation_successful');
} else {
// I get this error
$this->set('status', 'Save error message');
$this->set('user_data', $user);
$this->render('activation_fail');
}
debug($this->User->invalidFields());
} else {
$this->set('status', 'Account not found for this key');
$this->render('activation_fail');
}
} else {
$this->set('status', 'Empty key');
$this->render('activation_fail');
}
}
When I try the action test.com/users/activate/hashedkey I get the activation_fail template page with Save error message message.
If I printr the $user var I get the right user from cake's find method.
Where I'm wrong?
I think the problem may be in the way you're querying for the User record. When you do this:
$user = $this->User->find('first', array('activation_key' => $code));
The variable $user is populated with the User record as an array. You check to ensure it's not empty, then proceed; but the problem is that $this->User hasn't been populated. I think if you tried debug($this->User->id) it would be empty. The read() method works the way you're thinking.
You could try using the ID from that $user array to set the Model ID first, like so:
if (!empty($user)) {
$this->User->id = $user['User']['id']; // ensure the Model has the ID to use
$this->User->set(array (
'activation_key' => null,
'active' => 1
));
if ($this->User->save()) {
...
Edit: Well another possible approach is to use the $user array instead of modifying the current model. You said that you get back a valid user if you debug($user), so if that's true you can do something like this:
if (!empty($user)) {
$user['User']['activation_key'] = null;
$user['User']['active'] = 1;
if ($this->User->save($user)) {
...
This method works in the same way as receiving form data from $this->request->data, and is described on the Saving Your Data part of the book.
I'm curious though if there's another part of your setup that's getting in the way. Can other parts of your app write to the database properly? You should also check to make sure you aren't having validation errors, like their example:
<?php
if ($this->Recipe->save($this->request->data)) {
// handle the success.
}
debug($this->Recipe->validationErrors);