Is it possible to change the output width of PHP Shell_Exec? - php

I'm looking to parse the output that I'm getting back from PHP shell_exec. But some of the output that's returned is in tabular format and the data is wrapping within the columns as shown here...
Name Installed Proposed Message
Version version
Views Bulk Operations 7.x-3.3 7.x-3.4 Update available
(views_bulk_operations)
Chaos tools (ctools) 7.x-1.12 7.x-1.13 Update available
CAS (cas) 7.x-1.5 7.x-1.7 Update available
Custom Search 7.x-1.18 7.x-1.20 Update available
(custom_search)
Date iCal (date_ical) 7.x-3.5 7.x-3.9 Update available
Entity API (entity) 7.x-1.8 7.x-1.9 SECURITY UPDATE available
Field Group (field_group) 7.x-1.5 7.x-1.6 Update available
Media (media) 7.x-1.6 7.x-2.16 SECURITY UPDATE available
Insert (insert) 7.x-1.3 7.x-1.4 Update available
Views (views) 7.x-3.16 7.x-3.18 SECURITY UPDATE available
Views Data Export 7.x-3.0-beta8 7.x-3.2 SECURITY UPDATE available
(views_data_export)
Views PHP (views_php) 7.x-1.0-alpha 7.x-1.0- Update available
1 alpha3
Athena (athena) Unknown Unknown Project was not packaged
by drupal.org but
obtained from git. You
need to enable git_deploy
module
To make it easier to parse, I was hoping to be able to change the width of the output so the data doesn't wrap.
I assumed that specifying the width of the console with stty would work, but it doesn't. I tried this...
$output = shell_exec('stty cols 180; cd /; cd ' . $drupal_sites_folder_path . $list_of_drupal_sites[22] . '; drush pm-updatestatus');
...but the output width is still set to 80 cols.
Any suggestions on how to change the width of the output from shell_exec?

Related

Magento 2 - how to skip the cache when getting system config value?

I'm trying to get config values using:
$this->_scopeConfig->getValue(
$config_path,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
& it returns the cached value.
Is there any way to make it skip the cache without disabling it?
*I want the cache to be enabled but still bypass it for this value only.
**I also don't want to always clear the cache programmatically before getting it.
-- Any idea?
What you basically need is to query the database directly.
So Inject a Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory in your class.
Then you can query the database :
$collection = $collectionFactory->create();
$collection->addScopeFilter($scope, $scopeId, $section)
The $section is the path,
$scopeId the id of the store or website depending on the scope
& $scope is either "stores" or "website" or "default".

Laravel Excel - Get Active Cell or Row

That's a simple question.
I'm building a PHP Excel from scratch and is a very useful package.
I need to catch the active cell or row to know which cells to modify and customize, I checked all methods in the package and I didn't found something that helped me.
I'm inserting some data like this:
$sheet->appendRow(array(
$variable->value1,
$variable->value2,
$variable->value3,
));
And then I want to customize some things(This example I'm changing the background color), something like:
//The XXX is the last active row that I append some value before
$sheet->cells('XXXX',function ($cells){
$cells->setBackground('#34EC34');
});
There's some way to do find out the active cell or row to put in place of the 'XXX'? I found some question on Stack that someone was accessing by the variable $row, but I didn't found how to access....
go to class name "LaravelExcelWorksheet" in vendor/maatwebsite/excel/src/Maatwebsite/Excel/Classes/LaravelExcelWorksheet.php
Try to change method modifier of getStartRow from protected to public
You can use it with $sheet->getStartRow(), that's show you active row
Kaew's answer works, but to do this without modifying then LaravelExcel source, you can just use the method that getStartRow() uses internally - getHighestRow() - and add to the returned value if needed.
Here is the Laravel Excel 2.1 source for the getStartRow() method.

FileMaker - editing container field using php api and Insert from URL script

I am using php api for adding/editing/viewing a FileMaker database. I am using Filemaker pro 14 and FMS 14 in windows environment.
I am having an issue with adding/editing container fields. Tried the solution given in the following link: https://community.filemaker.com/thread/66165
It was success. The FM script is:
Goto Layout[ The layout that shows your container field ]
New Record/Request
Set Variable[$url ; Value:Get(ScriptParameter)]
Insert from URL [Select, No Dialog ; database_name::ContainerField ; $url]
Exit Script
I don't want to add new record. I have several container fields in the layout so it's not a solution to add a record for each one, and I need to be able to modify older records' container fields.
I tried modifying the script as follows:
Go to Layout ["products" (products)]
Go to Record/Request/Page [Last]
Open Record/Request
Set Variable [$url; Value: Get(ScriptParameter)]
Insert from URL [Select, No Dialog; products::brochure; $url]
Exit Script []
note: (Last) parameter is just experimental.
The php script is as follows:
$runscript = $fm->newPerformScriptCommand('products', 'addContainerData', 'http://link_to_uploded_file');
$result = $runscript->execute();
$result returns success, but the file wasn't inserted in the container field.
Somebody pointed to me that to use "Insert from URL" I have to specify a record ID. So I did the follows:
modified the php script to:
$editCommand = $fm->newEditCommand('products', $recordID, $editedData);
$editCommand->setPreCommandScript('addContainerData', 'http://url_to_my_uploaded_file');
$result = $editCommand->execute();
and the FM script (addContainerData) to
Set Variable [$url; Value: Get(ScriptParameter)]
Insert from URL [Select, No Dialog; products::brochure; $url]
Exit Script []
Also the result was success BUT without inserting the file to the container field.
What am I missing? What to do to be able to add container data to new/old records?
A possible workaround is to use PHP functions to encode the file to base 64 and set that value to a text field in FileMaker. Once there, you can have auto enter or a script to take the base 64 value and decode it to a container field. This works well especially for files with smaller file sizes.

where magento stores country full name

I have spent hours searching to find where magento stores full county name.
We can get a full list of countries using this code:
$_countries = Mage::getResourceModel('directory/country_collection')
->loadData()
->toOptionArray(false);
This will return an array with country code and name, I investigated the directory module, and found out this call gets data from the table
directory_county
But this table don't have full county name! So where is it stored?
and how is it retrieved using that call?
Thanks in advance.
Ok so to compensate for my wrong answer. Here is how this works:
/lib/Zend/Locale/Data/en.xml - if your store is in english, else another xml in the same directoery is read. Every country is there and its code under the xml tag <territory>
The xml is cached using the Zend_Cache_Core class.
/lib/Zend/Locale.php - function getTranslation invokes the lib/Zend/Cache/Core.php class
to load from the cache.
Example: If you change the name of some country in en.xml and clear the magento cache. You will see the change when u invoke your code again.
Full country names are not stored in database. Magento uses inbuilt Zend functionality.
Check file: lib/Zend/Locale/Data/Translation.php for full list.
Use the Zend_Local translation.
<?php
$code = 'EN';
echo Mage::app()->getLocale()->getTranslation($code, 'Territory', null, 2);
?>
Use the column 'iso2_code' from the table 'directory_country' for your $code.
Magneto only stores country codes in DB, and relies for names on Zend's Locale module to provide translated names, for different locale.
By the toOptionArray method it invokes the Zend_Locale class to get the translated value.
Refer $name = Mage::app()->getLocale()->getCountryTranslation($data['value']);, which gets to Mage_Core_Model_Locale and then to Zend_Locale.
It decides which of the node from the data to read, by the switch case statement in Zend_Locale_Data::getContent() line# 962, 963
Magento caches the names, so if you make any change to XML files, make sure to clean your cache folder to get what you seek.

Drupal 7.x: how to create a new node with PHP input format?

I want execute custom PHP script that will delete all nodes of a particular type (Feed items).
How to create a new node with PHP input format, so I can paste code into the node body? Please specify detailed steps.
$node_type = 'Feed items';
//fetch the nodes we want to delete
$result = db_query("SELECT nid FROM {node} WHERE type='%s'",$node_type);
while ($row = db_fetch_object($result)){
node_delete($row->nid);
$deleted_count+=1;
}
//simple debug message so we can see what had been deleted.
drupal_set_message("$deleted_count nodes have been deleted");
It's not entirely clear what you want to achieve. Do you simply want to execute that PHP code, once? Or whenever a node of a certain type is created?
If you just want to execute the PHP code once, you can install the devel module (http://drupal.org/project/devel) and paste your code in <your_site_url>/devel/php
--EDIT
Another option would be to create a php page that bootstraps Drupal and runs your code:
http://www.avenuewebmedia.com/drupalbootstrap-connect-drupal-external-php-script
OK, I managed myself how to do this: I had to enable the "PHP filter" module first (in Drupal core, disabled by default). In admin > Configuration > Content authoring > Text formats > Add text format, in "Enabled filters" mark "PHP evaluator", in Roles select 'admin', save configuration.
Then I created a new node (article), set the input format to PHP, pasted the code into the node body, added a title and clicked submit. Code has been executed. Sure, we need to delete the node when done.

Categories