Bad flag in substitute command: 'i'.sql - php

Running a database migrate in PHP (via Phing), I'm getting the following FAILED BUILD error:
Unable to open /site/thewebsite.co.uk/data/migrate-web_site-sed: 1: "s/[^a-z0-9]/-/gi": bad flag in substitute command: 'i'.sql for reading:
as well as several warnings along similar lines:
[PHP Error] fopen(/site/thewebsite.co.uk/data/migrate-web_site-sed 1: "s/[^a-z0-9]/-/gi": bad flag in substitute command: 'i'.sql): failed to open stream: No such file or directory [line 224 of /site/thewebsite.co.uk/vendor/phing/phing/classes/phing/tasks/ext/dbdeploy/DbDeployTask.php]
Does anyone have ideas about where to start looking for a resolution and/or the cause of the problem? The site files were cloned from a previously working repository and to my knowledge the DbDeployTask.php file has not been changed by any of my co-workers since the last working copy was cloned. I've had a look through the relevant .php file and I can't see any obvious issues. The section of the code referenced looks pretty standard:
protected function createOutputFile($file, $undo = false)
{
$fileHandle = fopen($file, "w+");
$sql = $this->generateSql($undo);
fwrite($fileHandle, $sql);
}
With createOutputFile called from within the deploy function:
protected function deploy()
{
// create deploy outputfile
$this->createOutputFile($this->outputFile, false);
// create undo deploy outputfile
$this->createOutputFile($this->undoOutputFile, true);
}
Where would people advise looking for the source of this issue, so our Apache server is able to deploy the development website correctly on this Macintosh?

Related

Facing issue while performing file reading operations in php

I am new to php . Currently as part of Migration activity we copied the existing php application to a new infrastructure where we are facing a strange issue.
Problem Statement:
From the php application,not able to read any file and it is not throwing any errors also. I used the following libraries and got the same behavior:
file_get_contents (This is the existing mechanism and I should use this one in the new infrastructure also)
Below two, checked to triage the issue:
readfile
fopen (tried with fopen just to see whether able to open like fopen($file, "r") or die( ),but this is also going to die condition
Issue Triaging
Made the below sample.php and make it available in my current server configuration. This is available by accessing through url (for e.g. https://myapplicationdomain/myapplication/sample.php). This php component is reading an input.txt which is in the same directory (actually this is the simulation of our problem)
<?php
ini_set('display_errors', 1); // show errors
error_reporting(-1);
//set your own error handler before the call
set_error_handler(function ($err_severity, $err_msg, $err_file, $err_line, array $err_context)
{
throw new ErrorException( $err_msg, 0, $err_severity, $err_file, $err_line );
}, E_WARNING);
echo "fopen url is";
var_dump(ini_get('allow_url_fopen'));
try{
$file ='input.txt';
if(is_readable($file)) {
echo "$file is readable \n"
} else {
echo "$file is not readable \n";
}
if(file_exists($file))
{
$homepage = file_get_contents($file);
var_dump($homepage);
echo "content is $homepage \n";
}else{
echo "file is not present \n";
}
}catch (Exception $e) {echo 'Error Caught $e';}
?>
Apache server is running using apache user and this user is having permission in the files and parent directories,
Following are the observations we got during triaging this:
When accessing through url for e.g. https://myapplicationdomain/myapplication/sample.php (i.e. through apache server).
a. functions is_readable & file_exists are returning true.
b. file_get_contents is returning blank and when I did var_dump, it is returning 'Null'
c. Confirmed the value of allow_url_fopen and it is returning 1 which is true
d. No errors are getting logged in this case.
e. Changed the permission of the 'input.txt' to see the permission behaviour. In that case,proper error got displayed in is_readable it self.So through this way ruled out the possibility of permission issue and also confirmed the error handler implementation is working fine.
f. Changed the location of input.txt to outside folders . ie. home/apache_user/ or root directory. Still file read operations are failing.
Able to run the same php code independently. i.e php sample.php .In this case,it is working as expected and all file reading operations are working fine.
3.Checked all the below php.ini configurations (removed all the values in disabled functions for testing)
a. open_basedir => no value
b. disabled_functions => no value
c. allow_url_fopen => true
Checked all the posts ,but not getting any idea how to proceed further. Following are version we are using: PHP 7.3.5 , CodeIgnitor framework and also configured php-fpm.
As per my understanding php library which apache was referring had some issues. Since it is a migration project and it is working fine in the current environment,copied the existing php folder (which was inside apache) and fpm binaries and configurations from the working environment to the new environment.Still not got any idea on exact root cause (as only read scenario was failing),but this got worked

Error 500 - include(user_id.php) [function.include]: failed to open stream (although code works locally) (Yii 1.x)

I am running Vagrant locally on my Windows PC, Vagrant is running CentOS and having a weird issue with something working fine locally on my Vagrant box, but getting a 500 error when pushing the code to my staging server.
Within my admin I have the following URL which grabs the id from the URL and uses that within a function to add some rows to a particular database table.
http://www.mysite.co.uk.192.168.0.155.xip.io/admin/settings/bulkclassroom/id/19312
This URL above in turn goes to my 'Settings' Controller and runs the follow function
public function actionBulkclassroom($id = null)
{
if (isset($id)) {
$model = new OrganisationClassroom();
$model->bulkAssignTeacherAllClassrooms($id);
}
}
This in turn uses the 'OrganisationClassroom' model and uses the following function to assign a teacher to all classrooms.
public function bulkAssignTeacherAllClassrooms($user_id = null)
{
if (!$user_id) return false;
$classes = OrganisationClassroom::model()->currentUserOrganisation()->findAll();
OrganisationClassroomsTeachersPivot::model()->deleteAll('user_id =:user_id ', array(':user_id'=> $user_id));
foreach($classes as $class)
{
$pivot = new OrganisationClassroomsTeachersPivot();
$pivot->classroom_id = $class->classroom_id;
$pivot->user_id = $user_id;
$pivot->save(false);
}
}
The code is pretty much self-explanatory and is working as expected when I run the code locally on my Vagrant box, however when I push the code to my staging server online I get the following error.
include(user_id.php) [function.include]: failed to open stream: No such file or directory
I am unsure why this is happening, nowhere in my code do I have an include(user_id.php) (I have done a search to double-check)
As the code & database tables are the same the issue can only be somehow related to my staging server setup somehow - can anyone suggest what is going on with this & how I can fix it?
For the record - this works 100% locally on my Vagrant box - it only gives the error on my staging server (has the same code & database structure) - the really odd thing is there is nowhere in my site do I have any includes referencing a file called user_id.php (I have double checked and there is definitely NO file called user_id.php on my local or remote staging server.
Any ideas?
check your file points to correct location that you have specified, mainly issue is with incorrect path to your file.

Weird Zend Framework issue - include_once is looking in the wrong folder

I've spent a lot of time troubleshooting this myself but none of what I've read solves my issue so I'm hoping I get some help here.
So anyway, I have written a PHP script that provides various functions to connect with Google Calendar. When I run this script directly using some inline test code to call my functions, everything runs fine. However, when I call the function from other scripts using 'require_once' to include it I get the following errors:
Warning: include_once(Zend\Gdata\Calendar\Extension\EventQuery.php) [function.include-once]: failed to open stream: No such file or directory in C:\Users\Luke Franklin\Clients\Tiers For Tea\Development\TiersForTea.com v1.1\lib\Zend\Loader.php on line 134
Warning: include_once() [function.include]: Failed opening 'Zend\Gdata\Calendar\Extension\EventQuery.php' for inclusion (include_path='.;C:\xampp\php\PEAR;C:\Users\Luke Franklin\Clients\Tiers For Tea\Development\TiersForTea.com v1.1\lib;C:\xampp\htdocs\TiersForTea.com\lib') in C:\Users\Luke Franklin\Clients\Tiers For Tea\Development\TiersForTea.com v1.1\lib\Zend\Loader.php on line 134
Your first thoughts might be that I'm not using the correct include path, but I have checked and rechecked this many times. I even tried hard coding the path. I'm quite sure that I'm using the correct path.
Now for the weird bit. If you look at the error you will notice the file Zend is trying to include: Zend\Gdata\Calendar\Extension\EventQuery.php. This file does not actually exist in the 'Extension' folder. It does exist in the parent folder though. If I just copy 'EventQuery.php' into the 'Extension' folder my script runs as expected. Weird, right?
So that does sorta solve my problem, but I would like to know what's going on here in-case it creates further issues. I should also note that I'm calling this script into an OpenCart module.
You might want to see some of my code so here's a snippet of the important bits, if you want more details just let me know:
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . realpath('\\lib') . PATH_SEPARATOR . "C:\\xampp\\htdocs\\TiersForTea.com\\lib");
require_once('Zend/Loader.php');
function connect() {
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Calendar');
I doubt the error exists in any of the Zend files as you have indicated it works correctly in your isolation tests.
The error is thrown from Zend_Loader which means something in your code is making reference to Zend_Gdata_Calendar_Extension_EventQuery.
Check the stack trace for the error if available to pinpoint the location. If that's not available, do a global find for that string. If you find any matches, you will need to change them to Zend_Gdata_Calendar_EventQuery.
Update
Seems this is a known bug(s)
http://framework.zend.com/issues/browse/ZF-7013
http://framework.zend.com/issues/browse/ZF-11959
It's an issue when your code registers an error handler using ErrorException. Apparently it's fixed in the 1.12 branch but hasn't made it to a release yet.
There's a patch in the 11959 bug report that fixes the issue

Includes not being found in PHP testing environment

I've inherited a site from a developer and they're using the following function to set the document root and define the mysql_connection for the site I assume:
function construct()
{
$this->mysql_link = mysql_connect("the_host", "username", "password");
mysql_select_db("thedatabase", $this->mysql_link);
$this->rootDir = $_SERVER['DOCUMENT_ROOT']."admin/";
$this->templateDir = $this->rootDir."templates/";
$this->isAdmin();
}
The trouble is, when I try to run this on my local development platform (Mac OSX Lion/PHP/Mysql) I keep getting the following error:
Warning: include(/Library/WebServer/Documentsadmin/templates/index/In The News/item.php) [function.include]: failed to open stream: No such file or directory in /Users/mycomputername/Sites/thewebsite.com/admin/editable.class.php on line 283
I'm relatively new to PHP and I'm assuming there's a problem with my php.ini file pointing to the wrong place as the web root but I'm not sure how to fix that or if that's even the problem I'm experiencing.
The database connection is functioning properly though.
Any help in diagnosing this is greatly appreciated.
Why not set rootDir to
$this->rootDir = dirname(__FILE__)."/admin";
instead? (add some more dirname()s around it if you need a higher level).
Assuming of course that the rootDir you need is somehow related to this file.

PHP - writing file - Permission denied for one script, but not another in the same directory

One of my PHP scripts writes data to a file. It is executing without issues. However my test code which calls the same methods in the same way and (for the purpose of trying to clear up this problem) is located in the same directory is reporting a:
failed to open stream: Permission denied
error.
My correctly executing script is simply:
try {
$printer = new PDFPrinter();
$FDFData = $printer->assembleFDFData(5);
$fdf_file = $printer->writeFDFFile($FDFData);
$printer->downloadForm($fdf_file);
}catch(Exception $e) {
echo $e->getMessage();
}
and my test code is:
function setUp() {
$this->printer = new PDFPrinter();
$this->FDFData = $this->printer->assembleFDFData(5);
}
function testWrite() {
try {
$this->printer->writeFDFFile($this->FDFData);
$this-assertTrue(true);
} catch(Exception $e) {
$this->assertTrue(false);
}
}
I know the testWrite test code is bad, but I just want to get it to stop throwing that exception first.
The script throws the exception when executing the writeFDFFile($this->FDFData); method as it tries to open the file to write. This is the code which fails:
$fp=fopen($fdf_file,'w')
I don't understand how 2 files in the same directory with the same permissions can work differently when executing the same code.
What could I be doing wrong?
Many thanks
How do you run standard and test code? Maybe you run standard code through apache (open in browser), but test code through directly php (run from IDE). And maybe apache have permissions, but php is not. And maybe working directory is difference ($fdf_file contains absolute path?).
Note also that "failed to open stream: Permission denied" is warning (not fatal error) and when you run standart code this warning will not stop execution. But PHPUnit convert warnings to exceptions and this warning will stop execution when you run code under PHPUnit.

Categories