GRAV git-sync plugin update crashing web-site, has anyone encountered/solved? - php

I've been using GRAV as a CMS for a small experimental site. I recently updated the git-sync plugin, and am suddenly stuck with a website that produces only errors, with no way to enter the admin gui (all web access to the site crashes with same errors), to downgrade the git-sync module, or for that matter, to upgrade the git-sync plugin if there is a fix.
I'm a developer that hasn't really thought much about web development in decades (my, how it's changed), so there are a few things I have to admit upfront. I don't know sht about php, and really don't care to if I don't have to.
The message I get (below) indicates that this is a php error. If this is a simple syntax fix please give me a heads up.
If you have any advice on a "cli" way to use the git-sync plugin to upgrade or downgrade, revert the git-sync, or any other hints, advise away. I'll dig in to more documentation and see if I end up answering my own question.
/[pathToUserHome]/grav/user/plugins/git-sync/classes/GitSync.php
*/
$paths = ['.'];
if (version_compare($version, '2.0', '<')) {
$add .= ' --all';
}
return $this->execute($add . ' ' . implode(' ', $paths));
}
public function commit($message = '(Grav GitSync) Automatic Commit')
{
$authorType = $this->getGitConfig('author', 'gituser');
if (defined('GRAV_CLI') && in_array($authorType, ['gravuser', 'gravfull'])) {
$authorType = 'gituser';
}
// get message from config, it any, or stick to the default one
$message = $this->getConfig('git', null)['message'] ?? $message;
// get Page Title and Route from Post
$pageTitle = $_POST['data']['header']['title']??'NO TITLE FOUND';
$pageRoute = $_POST['data']['route']??'NO ROUTE FOUND';
...
Arguments
1) "syntax error, unexpected '?'"
Whoops\Exception\ErrorException…
/user/plugins/git-sync/classes/GitSync.php : 223
$message = $this->getConfig('git', null)['message'] ?? $message;

Your new version of GRAV is using php7.0 features, like ?? operator, which is Null coalescing. Try to upgrade your php version to support new features, or downgrade GRAV.
Make a compatible version is also an option, but it could be time consumption idea. However, if your problems only in this particular file, you could replace:
// $message = $this->getConfig('git', null)['message'] ?? $message;
$message = isset($this->getConfig('git', null)['message']) ? $this->getConfig('git', null)['message'] : $message;
// $pageTitle = $_POST['data']['header']['title']??'NO TITLE FOUND';
$pageTitle = isset($_POST['data']['header']['title']) ? $_POST['data']['header']['title'] : 'NO TITLE FOUND';
// $pageRoute = $_POST['data']['route']??'NO ROUTE FOUND';
$pageRoute = isset($_POST['data']['route']) ? $_POST['data']['route'] : 'NO ROUTE FOUND';

Related

"Cannot use a scalar value as an array" error in Joomla 3.7.0 (html.php)

I recently updated my Joomla website to 3.7.0. and my contact form is not working properly; it is forever on "sending" status and never becomes "sent".
I do not think there is a problem with the module, but I believe the problematic code below is an issue, because it still persists after deactivating the module.
{
$options['relative'] = isset($options['relative']) ? $options['relative'] : false;
$options['pathOnly'] = isset($options['pathOnly']) ? $options['pathOnly'] : false;
$options['detectBrowser'] = isset($options['detectBrowser']) ? $options['detectBrowser'] : true;
$options['detectDebug'] = isset($options['detectDebug']) ? $options['detectDebug'] : true;
}
I am getting the error "Cannot use a scalar value as an array" in html.php.
Please help; this is my first StackOverflow post.
You can try declaring the variable $options, as an array, before using it.
$options = array();
Hope this will solve your issue. You can also check link, link2
Thanks & Regards,
Kaif

Switched from PHP version 4 to version 5.3 - code not working anymore

I recently swithced php version from 4 to 5.3. I now how some code that is not working anymore. I have a PHP script that fetches data from a form into a new form, when a user clicks a link.
First it recognizes the user/account and after that it finds the form data.
This is the code for the account data:
$account_info = ft_get_account_info($_SESSION["ft"]["account"]["account_id"]);
$emailadresse = ($account_info['email']);
$accountid = ($account_info['account_id']);
$firstname =($account_info['first_name']);
$lastname =($account_info['last_name']);
....
....
This works, and i can display the data through for example a:
<?php echo $_POST['firstname']; ?>
I then have this code in order to fetch and display the form data:
$submission_info = ft_get_submission_info($form_id, $submission_id);
$submission_id = ($submission_info['submission_id']);
$partname = ($submission_info['partname']);
$ponumber = ($submission_info['ponumber']);
....
....
<?php echo $_POST['partname']; ?>
This is not working anymore in version 5.3 of PHP.
Can anyone please tell what i need to re-write this code into, in order for it to work...????
Thanks in advance!
In addition to the comments i have this code for the ft_get_account_info:
$_SESSION["ft"]["account"] = ft_get_account_info($account_info["account_id"]);
And this for the ft_get_submission_info:
/**
* Returns all information about a submission. N.B. Would have been nice to have made this just a
* wrapper for ft_get_submission_info, but that function contains hooks. Need to revise all core
* code to allow external calls to optionally avoid any hook calls.
*
* #param integer $form_id
* #param integer $submission_id
*/
function ft_api_get_submission($form_id, $submission_id)
{
global $g_table_prefix, $g_api_debug;
// confirm the form is valid
if (!ft_check_form_exists($form_id))
{
if ($g_api_debug)
{
$page_vars = array("message_type" => "error", "error_code" => 405, "error_type" => "user");
ft_display_page("../../global/smarty/messages.tpl", $page_vars);
exit;
}
else
return array(false, 405);
}
if (!is_numeric($submission_id))
{
if ($g_api_debug)
{
$page_vars = array("message_type" => "error", "error_code" => 406, "error_type" => "user");
ft_display_page("../../global/smarty/messages.tpl", $page_vars);
exit;
}
else
return array(false, 406);
}
// get the form submission info
$submission_info = mysql_query("
SELECT *
FROM {$g_table_prefix}form_{$form_id}
WHERE submission_id = $submission_id
");
$submission = mysql_fetch_assoc($submission_info);
return $submission;
}
Nothing on the error reporting.
I don't know what your specific issue is, but I figure that if you use all the tools available to you for debugging, you'll be able to find your issue easily.
For development, you should always up your error reporting level to E_ALL ^ E_STRICT. You can find this setting in your php.ini file. E_STRICT specifically will help identify interoperability and compatibility issues, and is not included in E_ALL until PHP 5.4, according to the manual.
You may also want to use Netbeans and XDebug, which should allow you to step through your code line by line, which will simplify debugging immensely. There is a guide for setting up these tools here: Debugging PHP Source Code in the NetBeans IDE

Index data with Solr PHP Client

I'm using the Solr PHP Client and have the Solr 4.3.0 example up and running. I have not modified the schema.xml file. When I run this code I get a 400 error:
Uncaught exception 'Apache_Solr_HttpTransportException' with message '400' Status: Bad Request.'
The document does not show up in the index. Interestingly, If I restart Jetty, the document is indexed. Here's my code. I was wondering if I'm missing something. I thought this was an issue with my input matching the schema, but id seems to be the only required field and these other fields are in the schema. I'm not sure what to do.
require_once('SolrPhpClient/Apache/Solr/Service.php');
$solr = new Apache_Solr_Service('localhost', 8983, '/solr/');
if($solr->ping() == null){
die('could not ping solr');
}
$document = new Apache_Solr_Document();
$document->id = 'guid1';
$document->title = 'Title1';
$document->subject = 'The subject is solr';
$document->description = 'This is the description';
$solr->addDocument($document);
$solr->commit();
The full error message I get is
Fatal error: Uncaught exception 'Apache_Solr_HttpTransportException' with message ''400' Status: Bad Request' in C:\xampp\htdocs\dev\SolrPhpClient\Apache\Solr\Service.php:364
Stack trace:
#0 C:\xampp\htdocs\dev\SolrPhpClient\Apache\Solr\Service.php(829): Apache_Solr_Service->_sendRawPost('http://localhos...', '<commit expunge...', 3600)
#1 C:\xampp\htdocs\dev\indexerSOLR_PHP.php(20): Apache_Solr_Service->commit()
#2 {main} thrown in C:\xampp\htdocs\dev\SolrPhpClient\Apache\Solr\Service.php on line 364`
This is a known issue with Solr 4.x and calling commit from the Solr PHP Client. Please see
Bug #62332 - As of solr 4.0 the waitFlush parameter is removed for commit for the details and a patch to fix the issue.
That is what how I got the solution, I modified commit method. Added '&commit=true' to the _updateurl variable.
public function commit($expungeDeletes = false, $waitFlush = true, $waitSearcher = true, $timeout = 3600)
{
$expungeValue = $expungeDeletes ? 'true' : 'false';
$flushValue = $waitFlush ? 'true' : 'false';
$searcherValue = $waitSearcher ? 'true' : 'false';
//$rawPost = '<commit expungeDeletes="' . $expungeValue . '" waitFlush="' . $flushValue . '" waitSearcher="' . $searcherValue . '" />';
//$this->post=$rawPost;
return $this->_sendRawGet($this->_updateUrl.'&commit=true', $timeout);
}
You have change this line.
require_once('SolrPhpClient/Apache/Solr/Service.php'); => require_once('Service.php');
Maybe Service.php this file's path wrong. I try to changed this line. Then work successfully.
I had the same issue because I have installed an old version of the PHP Solr extension (0.9.11).
To get a the latest one:
pecl download solr-beta
tar xvzf solr-2.1.0.tgz # This can be different depending on the last release number
cd solr-2.1.0/
phpize
./configure
make
sudo make install
# add extension=solr.so to your php.ini / distribution extension loader
Thanks to this post.

Generating PHP code (from Parser Tokens)

Is there any available solution for (re-)generating PHP code from the Parser Tokens returned by token_get_all? Other solutions for generating PHP code are welcome as well, preferably with the associated lexer/parser (if any).
From my comment:
Does anyone see a potential problem,
if I simply write a large switch
statement to convert tokens back to
their string representations (i.e.
T_DO to 'do'), map that over the
tokens, join with spaces, and look for
some sort of PHP code pretty-printing
solution?
After some looking, I found a PHP homemade solution in this question, that actually uses the PHP Tokenizer interface, as well as some PHP code formatting tools which are more configurable (but would require the solution as described above).
These could be used to quickly realize a solution. I'll post back here when I find some time to cook this up.
Solution with PHP_Beautifier
This is the quick solution I cooked up, I'll leave it here as part of the question. Note that it requires you to break open the PHP_Beautifier class, by changing everything (probably not everything, but this is easier) that is private to protected, to allow you to actually use the internal workings of PHP_Beautifier (otherwise it was impossible to reuse the functionality of PHP_Beautifier without reimplementing half their code).
An example usage of the class would be:
file: main.php
<?php
// read some PHP code (the file itself will do)
$phpCode = file_get_contents(__FILE__);
// create a new instance of PHP2PHP
$php2php = new PHP2PHP();
// tokenize the code (forwards to token_get_all)
$phpCode = $php2php->php2token($phpCode);
// print the tokens, in some way
echo join(' ', array_map(function($token) {
return (is_array($token))
? ($token[0] === T_WHITESPACE)
? ($token[1] === "\n")
? "\n"
: ''
: token_name($token[0])
: $token;
}, $phpCode));
// transform the tokens back into legible PHP code
$phpCode = $php2php->token2php($phpCode);
?>
As PHP2PHP extends PHP_Beautifier, it allows for the same fine-tuning under the same API that PHP_Beautifier uses. The class itself is:
file: PHP2PHP.php
class PHP2PHP extends PHP_Beautifier {
function php2token($phpCode) {
return token_get_all($phpCode);
}
function token2php(array $phpToken) {
// prepare properties
$this->resetProperties();
$this->aTokens = $phpToken;
$iTotal = count($this->aTokens);
$iPrevAssoc = false;
// send a signal to the filter, announcing the init of the processing of a file
foreach($this->aFilters as $oFilter)
$oFilter->preProcess();
for ($this->iCount = 0;
$this->iCount < $iTotal;
$this->iCount++) {
$aCurrentToken = $this->aTokens[$this->iCount];
if (is_string($aCurrentToken))
$aCurrentToken = array(
0 => $aCurrentToken,
1 => $aCurrentToken
);
// ArrayNested->off();
$sTextLog = PHP_Beautifier_Common::wsToString($aCurrentToken[1]);
// ArrayNested->on();
$sTokenName = (is_numeric($aCurrentToken[0])) ? token_name($aCurrentToken[0]) : '';
$this->oLog->log("Token:" . $sTokenName . "[" . $sTextLog . "]", PEAR_LOG_DEBUG);
$this->controlToken($aCurrentToken);
$iFirstOut = count($this->aOut); //5
$bError = false;
$this->aCurrentToken = $aCurrentToken;
if ($this->bBeautify) {
foreach($this->aFilters as $oFilter) {
$bError = true;
if ($oFilter->handleToken($this->aCurrentToken) !== FALSE) {
$this->oLog->log('Filter:' . $oFilter->getName() , PEAR_LOG_DEBUG);
$bError = false;
break;
}
}
} else {
$this->add($aCurrentToken[1]);
}
$this->controlTokenPost($aCurrentToken);
$iLastOut = count($this->aOut);
// set the assoc
if (($iLastOut-$iFirstOut) > 0) {
$this->aAssocs[$this->iCount] = array(
'offset' => $iFirstOut
);
if ($iPrevAssoc !== FALSE)
$this->aAssocs[$iPrevAssoc]['length'] = $iFirstOut-$this->aAssocs[$iPrevAssoc]['offset'];
$iPrevAssoc = $this->iCount;
}
if ($bError)
throw new Exception("Can'process token: " . var_dump($aCurrentToken));
} // ~for
// generate the last assoc
if (count($this->aOut) == 0)
throw new Exception("Nothing on output!");
$this->aAssocs[$iPrevAssoc]['length'] = (count($this->aOut) -1) - $this->aAssocs[$iPrevAssoc]['offset'];
// post-processing
foreach($this->aFilters as $oFilter)
$oFilter->postProcess();
return $this->get();
}
}
?>
In the category of "other solutions", you could try PHP Parser.
The parser turns PHP source code into an abstract syntax tree....Additionally, you can convert a syntax tree back to PHP code.
If I'm not mistaken http://pear.php.net/package/PHP_Beautifier uses token_get_all() and then rewrites the stream. It uses heaps of methods like t_else and t_close_brace to output each token. Maybe you can hijack this for simplicity.
See our PHP Front End. It is a full PHP parser, automatically building ASTs, and a matching prettyprinter that regenerates compilable PHP code complete with the original commments. (EDIT 12/2011:
See this SO answer for more details on what it takes to prettyprint from ASTs, which are just an organized version of the tokens: https://stackoverflow.com/a/5834775/120163)
The front end is built on top of our DMS Software Reengineering Toolkit, enabling the analysis and transformation of PHP ASTs (and then via the prettyprinter code).

Drupal 7: how to get the modules list

How to get the modules list in Drupal as in admin/build/modules?
You can use drush pm-list --type=Module --status=enabled command for getting a list of installed modules.
Install "Drush" (a good option in any case, once you get used to it, you'll love it). It has a build in command to list all installed modules themes.
If you need to see the list of modules to display it elsewhere (this can be a security issue!), you can look into the way how drush does it (pm.drush.inc:218).
Furthermore there is a core function, but I don't know if this is what you want.
module_list($refresh = FALSE, $bootstrap_refresh = FALSE, $sort = FALSE, $fixed_list = NULL)
Here are more details.
http://api.drupal.org/api/drupal/includes!module.inc/function/module_list/7
If you want to list all the modules available to you, this should work with either Drupal 6 or Drupal 7:
<?php
// include_once('.' . base_path() . drupal_get_path('module', 'system') . '/system.admin.inc');
// Above line was intentionally commented out (see below).
$drupal_version = (int) VERSION;
$list_modules_function = '';
if ($drupal_version >= 7 && $drupal_version < 8) {
$list_modules_function = 'system_rebuild_module_data';
}
else if ($drupal_version >= 6 && $drupal_version < 7) {
$list_modules_function = 'module_rebuild_cache';
}
if (empty($list_modules_function)) {
$output = t('Oops... Looks like you are not using either version 6 or version 7 of Drupal');
}
else if (!function_exists($list_modules_function)) {
$output = t('Oops... Unable to find the function !function(). Try uncommenting the top line of this code.', array('!function' => $list_modules_function));
}
else {
$output = "<dl>\n";
$list_modules = $list_modules_function();
foreach ($list_modules as $module) {
$output .= "<dt>" . check_plain($module->info["name"]) . "</dt>\n";
$output .= "<dd>" . check_plain($module->info["description"]) . "</dd>\n";
}
$output .= "</dl>\n";
}
print $output;
?>
You can also use following commands to search specific modules.
If you want to list-down only commerce module from module list than
drush pml | grep commerce
On windows machine you cant use grep. So you have to use findstr
drush pml | findstr commerce
The following command will work, outputing list of all available modules along with the package they fall in, status and version.
drush pm-list --type=Module --status=enabled

Categories