How to cache and log table clear in magento 1.9.2?
I want to clear all magento cache and log with code. help me
Create clean.php and paste below code
function clean_log_tables() {
$xml = simplexml_load_file('./app/etc/local.xml', NULL, LIBXML_NOCDATA);
if(is_object($xml)) {
$db['host'] = $xml->global->resources->default_setup->connection->host;
$db['name'] = $xml->global->resources->default_setup->connection->dbname;
$db['user'] = $xml->global->resources->default_setup->connection->username;
$db['pass'] = $xml->global->resources->default_setup->connection->password;
$db['pref'] = $xml->global->resources->db->table_prefix;
$tables = array(
'aw_core_logger',
'dataflow_batch_export',
'dataflow_batch_import',
'log_customer',
'log_quote',
'log_summary',
'log_summary_type',
'log_url',
'log_url_info',
'log_visitor',
'log_visitor_info',
'log_visitor_online',
'index_event',
'report_event',
'report_viewed_product_index',
'report_compared_product_index',
'catalog_compare_item',
'catalogindex_aggregation',
'catalogindex_aggregation_tag',
'catalogindex_aggregation_to_tag'
);
mysql_connect($db['host'], $db['user'], $db['pass']) or die(mysql_error());
mysql_select_db($db['name']) or die(mysql_error());
foreach($tables as $table) {
#mysql_query('TRUNCATE `'.$db['pref'].$table.'`');
}
} else {
exit('Unable to load local.xml file');
}
}
function clean_var_directory() {
$dirs = array(
'downloader/.cache/',
'downloader/pearlib/cache/*',
'downloader/pearlib/download/*',
'media/css/',
'media/css_secure/',
'media/import/',
'media/js/',
'var/cache/',
'var/locks/',
'var/log/',
'var/report/',
'var/session/',
'var/tmp/'
);
foreach($dirs as $dir) {
exec('rm -rf '.$dir);
}
}
Then open ftp server and upload clean.php code in magento directory then run http://www.magentodirectory.com/clean.php?clean=log
Related
I write code for updating image it works when i upload new image. But when i dont upload image it caught exception as
Integrity constraint violation: 1048 Column 'photo' cannot be null
my query
update student set photo = , updated_at = 2018-12-14 10:38:35.
my controller code
function updatedata(Request $req)
{
dd($req->input());
$post=User::find($req->input('userid'));
$post->name=$req->input('name');
$post->address=$req->input('address');
$post->photo=$req->input('image');
$post->gender=$req->input('gender');
$post->hobbies= implode(',', Input::get('hobbies'));
$post->std=$req->input('std');
$requestData = $req->all();
if($req->hasFile('image'))
{
$image=$req->file('image');
$rules = array('file' => 'required|mimes:png,gif,jpeg'); // 'required|mimes:png,gif,jpeg,txt,pdf,doc'
$validator = \Illuminate\Support\Facades\Validator::make(array('file'=> $file), $rules);
$pathToStore=public_path('/');
if($validator->passes())
{
$filename = $file->getClientOriginalName();
$extension = $file -> getClientOriginalExtension();
$picture = sha1($filename . time()) . '.' . $extension;
$upload_success = $file->move($pathToStore, $picture);
if($upload_success)
{
//if success, create thumb
$image = Image::make($picture)->resize(600, 531)->save($pathToStore,$picture);
$oldfilename=$user->photo;
$user->photo=$filename;
Storage::delete($oldfilename);
}
}
$requestData['photo'] = "$pathToStore/{$picture}";
}
$post->update($requestData);
return redirect()->route('show');
}
remove $user->photo=$req->input('image'); outside of if condition and set null to true and default null in database image field.
function updatedata(Request $req)
{
//dd($req->input());
$user = User::find($req->input('userid'));
if ($req->hasFile('image')) {
$image = $req->file('image');
$filename = time() . '.' . $image->getClientOriginalExtension();
$location = public_path('/' . $filename);
Image::make($image)->resize(100, 100)->save($location);
$oldfilename = $user->photo;
Storage::delete($oldfilename);
$input['photo'] = $filename;
}
else {
$input['photo'] = $user->photo;
}
$input['name'] = $req->input('name');
$input['address'] = $req->input('address');
$updateUser = User::where('id', $req->input('userid'))->update($input);
return redirect()->route('show');
}
it looks like you have add not null constraints in column 'photo'. So remove it and set default image path to it.
set a default path of image if image not upload
if($req->hasFile('image'))
{
$image=$req->file('image');
$filename=time().'.'.$image->getClientOriginalExtension();
$location=public_path('/'.$filename);
Image::make($image)->resize(100,100)->save($location);
$oldfilename=$user->photo;
$user->photo=$filename;
Storage::delete($oldfilename);
}else {
$user->photo = "set/to/default/path/image.jpg";
}
otherwise update user table migration look like this and migrate again
$table->string('photo')->nullable();
You should try this:
function updatedata(Request $req)
{
//dd($req->input());
$user=User::find($req->input('userid'));
$user->name=$req->input('name');
$user->address=$req->input('address');
if($req->hasFile('image'))
{
$image=$req->file('image');
$filename=time().'.'.$image->getClientOriginalExtension();
$location=public_path('/'.$filename);
Image::make($image)->resize(100,100)->save($location);
$oldfilename=$user->photo;
$user->photo=$filename;
Storage::delete($oldfilename);
$user->photo=$req->input('image');
} else {
$user->photo="notAvailable.jpg";
}
$user->save();
return redirect()->route('show');
}
According to Vimeo it is possible to send the upload directly to their server, without having to use the hosting server of the site.
https://help.vimeo.com/hc/en-us/articles/224970068-Can-I-upload-directly-to-Vimeo-and-skip-my-server-entirely-
With documentation:
https://developer.vimeo.com/api/upload/videos#http-post-uploading
But, I did not find any examples or I could understand how to do this
Resolved
Download API Vimeo: API Vimeo
Load API: File: vimeo_init.php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
// Load the autoloader
if (file_exists('/vimeo/autoload.php')) {
// Composer
require_once('/vimeo/autoload.php');
} else {
// Custom
require_once(__DIR__ . '/vimeo/autoload.php');
}
// Load the configuration file.
if (!function_exists('json_decode')) {
throw new Exception(
'We could not find `json_decode`. `json_decode` is found in PHP 5.2 and up, but not found on many Linux ' .
'systems due to licensing conflicts. If you are running Ubuntu try `sudo apt-get install php5-json`.'
);
}
$config = json_decode(file_get_contents(__DIR__ . '/vimeo_config.json'), true);
if (empty($config['client_id']) || empty($config['client_secret'])) {
throw new Exception(
'We could not locate your client id or client secret in "' . __DIR__ . '/vimeo_config.json". Please create one, ' .
'and reference config.json.example'
);
}
return $config;
Config API KEY: File vimeo_config.json
{
"client_id" : "",
"client_secret" : "",
"access_token" : ""
}
File POST PHP: File Upload Video
use Vimeo\Vimeo;
use Vimeo\Exceptions\VimeoUploadException;
$config = require(__DIR__ . '/vimeo_init.php');
$files = array($_FILES['video_arquivo']['tmp_name']); //array_shift($files);
if (empty($config['access_token'])) {
throw new Exception(
'You can not upload a file without an access token. You can find this token on your app page, or generate ' .
'one using `auth.php`.'
);
}
$lib = new Vimeo($config['client_id'], $config['client_secret'], $config['access_token']);
$uploaded = array();
foreach ($files as $file_name) {
try {
$uri = $lib->upload($file_name, array(
'name' => 'titulo',
'description' => 'descricao'
));
$video_data = $lib->request($uri);
if ($video_data['status'] == 200) {
$video_vimeo = $video_data['body']['link'];
}
$uploaded[] = array('file' => $file_name, 'api_video_uri' => $uri, 'link' => $link);
} catch (VimeoUploadException $e) {
$result["is_valid"] = false;
$result["message"] = $e->getMessage();
}
}
I have a onBootstrap method in module.php file. I want to use this function to also store user log details into the mysql db. Not able to use persist and flush methods. Any thoughts, how to create a db connection?
Thanks in advance
public function onBootstrap(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
$eventManager->attach('finish', array($this, 'outputCompress'), 100);
$e->getApplication()->getEventManager()->getSharedManager()->attach('Zend\Mvc\Controller\AbstractActionController', 'dispatch', function($e) {
$controller = $e->getTarget();
$app = $e->getApplication();
$sm = $app->getServiceManager();
$auth = $sm->get('zfcuser_auth_service');
$routeMatch = $e->getRouteMatch();
// $name = $auth->getresolvedIdentity('id');
//echo "<pre>"; var_dump($auth); var_dump($routeMatch);
if($routeMatch && $auth){
$Userlog = new Userlog();
$Userlog->setUserid(10);
$Userlog->setUsername('abc');
$Userlog->setUrl_loaded('xyz');
$this->getObjectManager()->persist($Userlog);
$this->getObjectManager()->flush();
}
I have a database with aproximately 200 tables. I want to clone a certain user-account in this database. Is this possible in mysql?
With cloning I mean to create a new user with the same 'settings' as the user with id 14.
A quick google search reveals that you in fact can do this. There is a utility called " "mysql user clone", that lets you surprisingly clone a user for mysql.
If you check out the manual I'm sure it provides you with great tips about how to use it, for instance, this quote:
EXAMPLES
To clone joe as sam and sally with passwords and logging in as root on the local machine, use this command:
$ mysqluserclone --source=root#localhost \
--destination=root#localhost \
joe#localhost sam:secret1#localhost sally:secret2#localhost
# Source on localhost: ... connected.
# Destination on localhost: ... connected.
# Cloning 2 users...
# Cloning joe#localhost to user sam:secret1#localhost
# Cloning joe#localhost to user sally:secret2#localhost
# ...done.
since it appears #Nanne's approach, mysqluserclone is EOL / not supported by Oracle, i wrote a similar utility in PHP, usage:
<?php
$db = new \PDO("mysql:host={$db_creds->dbhost};dbname={$db_creds->dbname};charset=utf8mb4;port=" . $db_creds->dbport, $db_creds->superuser_user, $db_creds->superuser_pass, array(
\PDO::ATTR_EMULATE_PREPARES => false,
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC
));
Mysqluserclone::clone_account($db, "original username", "cloned username");
and this part of the code may be of particular interest:
if (0) {
echo "the following SQLs will clone this account:\n";
echo implode("\n\n", $sqls_for_cloning) . "\n\n";
die();
}
<?php
class Mysqluserclone{
private function __construct(){
// by making this private, we ensure nobody try to instantiate us.
}
public static function clone_account(\PDO $db_connected_as_superuser, string $original_name, string $clone_name): void
{
$db = $db_connected_as_superuser;
$sqls_for_cloning = [];
$sql = "SELECT COUNT(*) FROM mysql.user WHERE User = " . $db->quote($clone_name);
if (0 !== $db->query($sql)->fetch(\PDO::FETCH_NUM)[0]) {
throw new \InvalidArgumentException("clone name already exists!");
}
$sql = "SELECT * FROM mysql.user WHERE User = " . $db->quote($original_name);
$current_user_one_for_each_host = $db->query($sql)->fetchAll(\PDO::FETCH_ASSOC);
foreach ($current_user_one_for_each_host as $user_record) {
$user_record["User"] = $clone_name;
$sql = "INSERT INTO mysql.user SET \n";
foreach ($user_record as $name => $val) {
$sql .= self::mysql_quote_identifier($name) . " = " . self::mysql_quote_better($db, $val) . ",\n";
}
if (! empty($user_record)) {
$sql = substr($sql, 0, - strlen(",\n"));
}
$sql .= ";";
$sqls_for_cloning[] = $sql;
$sqls_for_cloning[] = "FLUSH PRIVILEGES;"; // YES this is required, otherwise you might get "grant not allowed to create accounts" errors
$grants_raw_sql = 'SHOW GRANTS FOR ' . $db->quote($original_name) . '#' . $db->quote($user_record['Host']) . ";";
try {
$grants_raw = $db->query($grants_raw_sql)->fetchAll(\PDO::FETCH_NUM);
} catch (\Throwable $ex) {
// somehow an empty grant table is a mysql error, not an empty rowset.. ignore it.
$grants_raw = [];
}
$grants_raw = array_map(function (array $arr): string {
if (count($arr) !== 1) {
throw new \LogicException("mysql layout for SHOW GRANTS has changed? investigate");
}
return $arr[0];
}, $grants_raw);
$original_name_as_identifier = self::mysql_quote_identifier($original_name);
$clone_name_as_identifier = self::mysql_quote_identifier($clone_name);
foreach ($grants_raw as $grant) {
if (false === strpos($grant, $original_name_as_identifier)) {
throw new \LogicException("original grant without original name as identifier? investigate");
}
$grant = self::str_replace_last($original_name_as_identifier, $clone_name_as_identifier, $grant);
$grant .= ";";
$sqls_for_cloning[] = $grant;
}
}
if (! empty($sqls_for_cloning)) {
$sqls_for_cloning[] = "FLUSH PRIVILEGES;";
}
if (0) {
echo "the following SQLs will clone this account:\n";
echo implode("\n\n", $sqls_for_cloning) . "\n\n";
die();
}
foreach ($sqls_for_cloning as $clone_sql) {
$db->exec($clone_sql);
}
}
private static function mysql_quote_identifier(string $identifier): string
{
return '`' . strtr($identifier, [
'`' => '``'
]) . '`';
}
private static function mysql_quote_better(\PDO $db, $value): string
{
if (is_null($value)) {
return "NULL";
}
if (is_int($value)) {
return (string) $value;
}
if (is_float($value)) {
return number_format($value, 10, '.', '');
}
if (is_bool($value)) {
return ($value ? "1" : "0");
}
return $db->quote($value);
}
private static function str_replace_last(string $search, string $replace, string $subject): string
{
$pos = strrpos($subject, $search);
if ($pos !== false) {
$subject = substr_replace($subject, $replace, $pos, strlen($search));
}
return $subject;
}
}
I'm creating a file upload system in CodeIgniter, and I have a form that asks for a file name before it uploads to the database. It uses my controller to upload the file to the server. Currently the controller is working, but I need to insert the file name into the table.
upload.php:
function do_upload()
{
$config['upload_path'] = './gfiles/';
$config['allowed_types'] = 'gif|jpg|jpeg|bmp|png|psd|pdf|eps|ai|zip|indd|qxt';
$config['encrypt_name'] = 'TRUE';
//$config['max_size'] = '100';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->db->insert('files', $_POST);
}
}
Does anyone have any pointers on how to get the file name into the database properly? The code above also encrypts the filename. Thank you.
$data = array('upload_data' => $this->upload->data()); should contain what you are looking for.
do print_r($data) and you should see the original and encrypted filename.