How to get sitename from alfresco folder - alfresco

I would like to get sitename from an Alfresco folder using Java.
Actually, I could retrieve file name and folder but I could not get sitename property.
nodeService.getProperty(parent, PROP_QNAME_MY_NAME);
Could you please help me to get sitename from parent or nodeService?

You should use SiteService:
* #param nodeRef the node whose containing site's info is to be found.
* #return SiteInfo site information for the containing site or <code>null</code> if node is not in a site.
SiteInfo siteInfo = siteService.getSite(NodeRef nodeRef);
String siteName = siteInfo.getShortName();

Related

Woocommerce change order download files

I am trying to manipulate the download URL link for files inside an order.
Basically, I have a use case when a download product is bought I need to add files to the order to be able to download it. So I cannot add an order ID to a product because there is no order at that moment.
Point is, every downloadable product needs to have a dynamic link because it will be generated on the fly .
So how can I add data to the product download URL link ->
WooCommerce offers 2 filters that can be used to achieve what you are looking for:
A) woocommerce_download_product_filepath used to specify what URL contains the file to be downloaded and it takes the following parameters:
#param string $file_path File path
#param string $email_address Email address
#param WC_Order|bool $order Order object or false
#param WC_Product $product Product object
#param WC_Customer_Download $download Download data
And it is registered like this:
add_filter( 'woocommerce_download_product_filepath', 'change_woocommerce_file_download_path', 10, 5 );
More info here https://wp-kama.com/plugin/woocommerce/hook/woocommerce_download_product_filepath
B) woocommerce_file_download_filename used to manipulate the downloaded file's name and it takes the following parameters:
#param string $filename Downloadable file name.
#param int $product_id WC product id
And it is registered like this:
add_filter( 'woocommerce_file_download_filename', 'change_woocommerce_file_download_filename', 10, 2 );
More info here https://wp-kama.com/plugin/woocommerce/hook/woocommerce_file_download_filename

Host matching in Symfony3 routes

I have a website (example.com) which has a subdomain for the customer area like customer.example.com. Now I want to add a different subdomain which is exactly the same as that website but only has a different images.
This should result in example.com equals demo.example.com and customer.exmaple.com equals customer.demo.example.com.
At the moment I have the current route annotation bind to the class for the customer side:
/**
* Customer links
* #Route(host="customer.%domain%")
*/
class CustomerController extends Controller
{
(domain is defined in config.yml)
I tried changing that to match hosts like so:
/**
* Customer links
* #Route(
* host="customer.{domain}",
* defaults={"domain"="%domain%"},
* requirements={"domain"="%domain%|demo.%domain%"}
* )
*/
But this won't work since you need to provide a default parameter for domain, and this will always be the value in this case. So the URL works, but every other link will redirect you back to customer.domain.com
I tried the same thing in routing.yml which had the same results.
Is it possible to have a dynamic domain/subdomain, and if so, how could I do it?

Sonata media bundle - get pdf file by name or change filename on update

I currently use SonataAdminBundle and SonataMediaBundle.
I have a problem with the media bundle files because my pdf file is not saved with its name but with md5 or another format.
For example:
media table
id : 1
name : iphone.pdf
provider_reference : 9a0b7a35131e23f91666324562c52f08b7cb6604.pdf
I don't want to get my pdf by this:
9a0b7a35131e23f91666324562c52f08b7cb6604.pdf
but with its name ( iphone.pdf ).
I want to know if it's possible to:
get the pdf file by name?
or
save my pdf file with a particular name?
use this in your Twig so you can download it with its name:
{{ path('sonata_media_download', {'id': (your media object here|sonata_urlsafeid)}) }}
To see it without download, I'm searching for that , I'll be back if I find something.
Good luck!
If you want get public URL for file in PHP-code, you can use something like this (code from my Application\Sonata\MediaBundle\Helper\MediaHelper)
public function getPublicUrl(Media $media, $format = 'reference')
{
if (!$media) {
return '';
}
/** #var ImageProvider $provider */
$provider = $this->container->get($media->getProviderName());
$format = $provider->getFormatName($media, $format);
return $provider->generatePublicUrl($media, $format);
}
If you need link in twig, you can find special helper in SonataMedia official docs (I forgot name of helper).

Delete image on database delete symfony2

Symfony Forms
I have this all working correctly. One thing that I am not sure is how to delete the image that is uploaded in the uploads folder when the associated entry in the database is deleted.
I really just need an idea on how to do it to get headed in the right direction.
Thanks in advance.
You are both correct I did a var dump on the code that was in the entity...
/**
* #ORM\PostRemove
*/
public function removeUpload()
{
if(file_exists($file)) {
if ($file = $this->getAbsolutePath()) {
unlink($file);
}
}
}
if file exists $file was showing an empty variable. In the upload it saves the variable as $logo
I changed the code to the following
/**
* #ORM\PostRemove
*/
public function removeUpload() {
// ** Original Code used file but logo has the name in it.
if(file_exists($this->getAbsolutePath())) {
if ($this->getUploadRootDir() . $this->logo = $this->getAbsolutePath()) {
unlink($this->logo);
}
}
}
It now deletes the file correctly. Thank you both.
In your delete action, you would have to delete the file manually. I assume you will be storing the file path in the database, so this should be relatively easy.
$path = ....//query db to get the path to the file
if($path){
unlink($path);
}
//now you can delete the record in the database
See php docs for deleting a file
What you are probably searching for are Doctrine2 Lifecycles. Just add a method to your entity:
/**
* #ORM\PreRemove
*/
public function deleteImage()
{
// unlink your image and what not.
}
Also don't forget the #ORM\HasLifecycleCallbacks() annotation for your entity class.

Facing problems in creating video library using Brightcove Media API

I am facing a problem related to making a video library on my Drupal website using brightcove media API . Can someone please tell me how do I pull out the details of author, date posted and details about the video which I need to display along with the video on my page. I have somehow managed to display the video on my page but I am still struggling with pulling out other details and displaying it along with my video on the page. For your information, I am working in Drupal 6. Can someone please help me out with this??
You might want to check out the following helpful links:
http://opensource.brightcove.com/project/PHP-MAPI-Wrapper/
http://developer.brightcove.com/en/documentation
I'm not sure I understand what you mean by "author", Brightcove currently does not track audit trail type info. For example you cannot query who uploaded the video. Only metadata that belongs to the video.
Assuming "Author" is a custom field, you can obtain that info by doing a call something like:
/**
* function custom_search() - search specified field for given value
* #param string [$term] - Required. The value to search for.
* #param string [$criteria] - any, all, or none. Default: any.
* #param string [$search_field] - Specify the field to look for the search term in. Default: search_text.
*/
/** Available search fields: display_name, reference_id, tag, custom_fields, search_text.
* Using search_text is the equivalent of searching displayName, shortDescription and longDescription fields
* and is also the same as omitting the field name altogether
*/
function custom_search($term, $criteria = 'any', $search_field = 'search_text') {
$bc = create_bcmapi();
$params = array(
'video_fields' => 'id,name,shortDescription,referenceId,tags,custom_fields'
);
$terms = array($criteria => $search_field.':'.$term);
$data['videos'] = $bc->search('video', $terms, $params);
return $data;
}
Sorry this is late, but maybe it will help someone else.

Resources