Magento cron check if file exist - .htaccess

Hi i have some issues with dissapearing .htaccess file in magento/media catalogue.
I want to set cron to check if this file exists and if not i want to refresh/push it to that catalogue.
config.xml file
<crontab>
<jobs>
<watchdog_htaccess>
<schedule>
<cron_expr>*/15 * * * *</cron_expr>
</schedule>
<run>
<model>mypage_watchdog/Media::updateHtaccess</model>
</run>
</watchdog_htaccess>
</jobs>
</crontab>
I wrote php function:
public function updateHtaccess(){
$mediaCatalog = Mage::getBaseDir('media');
$htaccess = '.htaccess';
$file = $mediaCatalog . '/' . $htaccess;
if ( !file_exists($file) ){
$mediaCatalog->import($file);
}
}
I use magento 1.9
What should i do to make it work?

Related

How to replace specific section of text in a file, with text from url in bash?

I am trying to replace some text in a file with text from a url link. I have gotten close, but the result has unintended complications.
Here is the text of the file I need to do this with (wp-config.php):
<?php
/**
* The base configuration for WordPress
*
* The wp-config.php creation script uses this file during the installation.
* You don't have to use the web site, you can copy this file to "wp-config.php"
* and fill in the values.
*
* This file contains the following configurations:
*
* * Database settings
* * Secret keys
* * Database table prefix
* * ABSPATH
*
* #link https://wordpress.org/support/article/editing-wp-config-php/
*
* #package WordPress
*/
// ** Database settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'database_name_here' );
/** Database username */
define( 'DB_USER', 'username_here' );
/** Database password */
define( 'DB_PASSWORD', 'password_here' );
/** Database hostname */
define( 'DB_HOST', 'localhost' );
/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );
/** The database collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );
/**##+
* Authentication unique keys and salts.
*
* Change these to different unique phrases! You can generate these using
* the {#link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}.
*
* You can change these at any point in time to invalidate all existing cookies.
* This will force all users to have to log in again.
*
* #since 2.6.0
*/
define( 'AUTH_KEY', 'put your unique phrase here' );
define( 'SECURE_AUTH_KEY', 'put your unique phrase here' );
define( 'LOGGED_IN_KEY', 'put your unique phrase here' );
define( 'NONCE_KEY', 'put your unique phrase here' );
define( 'AUTH_SALT', 'put your unique phrase here' );
define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
define( 'LOGGED_IN_SALT', 'put your unique phrase here' );
define( 'NONCE_SALT', 'put your unique phrase here' );
/**##-*/
/**
* WordPress database table prefix.
*
* You can have multiple installations in one database if you give each
* a unique prefix. Only numbers, letters, and underscores please!
*/
$table_prefix = 'wp_';
/**
* For developers: WordPress debugging mode.
*
* Change this to true to enable the display of notices during development.
* It is strongly recommended that plugin and theme developers use WP_DEBUG
* in their development environments.
*
* For information on other constants that can be used for debugging,
* visit the documentation.
*
* #link https://wordpress.org/support/article/debugging-in-wordpress/
*/
define( 'WP_DEBUG', false );
/* Add any custom values between this line and the "stop editing" line. */
/* That's all, stop editing! Happy publishing. */
/** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) ) {
define( 'ABSPATH', __DIR__ . '/' );
}
/** Sets up WordPress vars and included files. */
require_once ABSPATH . 'wp-settings.php';
I need to replace the section of salts with the ones in this link:
https://api.wordpress.org/secret-key/1.1/salt/
I believe there are escape characters in the salts complicating things for me as I am new to bash. Here is the closest I have gotten but this took some help:
cp wp-config.php wp-config.bak
curl https://api.wordpress.org/secret-key/1.1/salt/ | awk -F "'" 'NR==FNR {a[$2]=$4;next} {$4=a[$2]}1' OFS="'" - wp-config.php > wp-config.tmp
mv wp-config.tmp wp-config.php
cat wp-config.php
Once again, this creates new issues, while it does replace the salts section it also makes the file unreadable. Hoping someone can help me tweak this, or show me a better way to accomplish this.
Since you trust the contents of the URL, you could replace (once) the defines lines in wp-config.php with:
require '/path/to/salts';
and then when you need new salts, just do something like:
url='https://api.wordpress.org/secret-key/1.1/salt/'
if salts=$(curl -fs "$url"); then
printf '<?php\n%s\n' "$salts" > /path/to/salts
fi
You'll need to ensure that your webserver process has permission to read the salts file.
This is probably what is causing wp-config.php to become unreadable when you do your awk/mv:
if the user creating the temporary file creates it as rw------- for example (or as rw-r---- but the webservice process does not run in the same group), then the webserver process will be unable to read the file.

How to get products list in Shopware Plugin

I am having very hard time getting list of products to be displayed in the landing page using a plugin.
The documentation found insufficient in this regard.
I got stuck here:
$controller = $args->get('subject');
$view = $controller->View();
$view->addTemplateDir(
__DIR__ . '/Views'
);
maybe this will help you in the approach to the issue
//get current article Id
$articleId = $view->sArticle['articleID'];
$query = $this->container->get('dbal_connection')->createQueryBuilder();
$query->select('s_articles.name')
->from('s_articles')
->where('s_articles.id = :id')
->setParameter('id', $articleId);
$single = $query->execute()->fetchColumn();
$view->assign('article_name', $single);
$view->assign('article_cat', ''.$view->sArticle['linkDetails'].'' );
/**
* Add template to the directory plugin
*/
$view->addTemplateDir($this->container->getParameter('gwen_cinema.plugin_dir') . '/Resources/Views');

MySQL: “Too many connections” in opencart 2.0.3.1

I recently installed opencart 2.0.3.1. Since I have installed opencart I get the below error
Warning: mysqli::mysqli() [mysqli.mysqli]: (08004/1040): Too many connections in /home/burhanie/public_html/store/system/library/db/mysqli.php on line 7
Notice: Error: Could not make a database link (1040) Too many connections in /home/burhanie/public_html/store/system/library/db/mysqli.php on line 10
Warning: mysqli::close() [mysqli.close]: Couldn't fetch mysqli in /home/burhanie/public_html/store/system/library/db/mysqli.php on line 58
Below is the opencart code from file mysqli.php
public function __construct($hostname, $username, $password, $database, $port = '3306') {
$this->link = new \mysqli($hostname, $username, $password, $database, $port);
if ($this->link->connect_error) {
trigger_error('Error: Could not make a database link (' . $this->link->connect_errno . ') ' . $this->link->connect_error);
exit();
}
$this->link->set_charset("utf8");
$this->link->query("SET SQL_MODE = ''");
}
Below is the screen shot of phpmyadmin advisor. which states opencart is using too many connection. This seems to be a bug

How to set the default directory in Komodo from an an extension?

I'm working on a KomodoIDE/KomodoEdit extension that creates a new file and then opens it in a new editing tab using
...
var obsvc = Components.classes["#mozilla.org/observer-service;1"].
getService(Components.interfaces.nsIObserverService);
...
Display.initWithPath(Target.path);
Display.append(what);
try {
obsvc.notifyObservers(null, 'open-url', "file://" + Display.path);
} catch (e) {
alert(e);
}
which works, but I would also like it to set Komodo's default directory to the same directory where this file lives, but I don't see a way to do that automatically.
I found the doCommand...
ko.commands.doCommand('cmd_openDirectory')
but this just launches a file dialog that asks the user to pick a directory. I'd like to do something to set it programatically using something like...
obsvc.notifyObservers(null, 'open-directory', "file://" + Display.path);
(which I know doesn't work but is sort of the idea).
I just discovered that the ko.places.manager object has a function to set the default Places window-pane directory. Below is an example of how I used it. The uri should be set to the full directory path and, in the case of Windows, backslashes should get escaped...
function SetPlace(ko, uri) {
try {
ko.places.manager.openDirURI("file:///" + uri.replace(/\\/g, "\\\\") );
} catch(e) {
alert("Could not set place to: " + uri.replace(/\\/g, "\\\\") + "\n" + e);
}
}
The nsIFile interface provides this:
// Get current working directory
var file = Components.classes["#mozilla.org/file/directory_service;1"].
getService(Components.interfaces.nsIProperties).
get("CurProcD", Components.interfaces.nsIFile);
The Komodo preferences service would also be an option:
var gprefs = Components.classes["#activestate.com/koPrefService;1"].
getService(Components.interfaces.koIPrefService).prefs;
gprefs.setStringPref("mruDirectory", "Display.path);
References
How do I get the path of the project folder
Getting Special Files
Komodo JS Macro - insert a relative path from the current editor file
mruDirectory
XPCOM API Reference
Komodo Profile Structure
Where does Komodo Store File Preferences
Getting/Setting a Komodo Preference

NetSuite SuiteScript to modify file in the file cabinet

We have files within the NetSuite file cabient which need to be updated (the url field has changed). I found the noted article on this site but there is no code example to perform the requested. It indicates to use the nlapiLoadFile and nlapiSubmitFile calls; would anyone be able to assist with a code example?
Link:
Can Netsuite Suitescript modify a file in the file cabinet?
Ya, it seems a bit odd. The only way I found is:
Load The File
Create a file handle with:
Set the file name to one that you intended.
Set the content to intended one
Set the folder and submit.
I have attached a code snippet
var file = nlapiLoadFile(file_id);
var content = file.getValue();
content = '...put your content...';
file = nlapiCreateFile(file.getName(), 'FILE TYPE', content);
file.setFolder(required_folder_id);
nlapiSubmitFile(file);
Hope this helps.
There is no special API function to edit an existing file, you could take the details of the existing file and create a new file with the same details but changing the data field only and deleting the old file.
var start = function(request, response)
{
var fileId = "107524";//get the existing file id
var file = nlapiLoadFile(fileId);
var data = file.getValue();
var name = file.getName();
var folderId = file.getFolder();
var fileType = file.getType();
nlapiDeleteFile(fileId);//delete the older file
data += ",this is the appended data";//change the data
var newFile = nlapiCreateFile(name, fileType, data);//create a new file with the same details
newFile.setFolder(folderId);
nlapiSubmitFile(newFile);//submit it
}
Do you mean file instead of field? If you use nlapiLoadFile(/path/file), you can then use getURL() to provide a link to that file.
NetSuite does not have a edit file kind of an API. You will have to load the original file, modify the contents as per your needs and then submit that data by creating a new file with same file name and inside the same folder. This simply overrides the existing file.
Here's the code sample:
var original = nlapiLoadFile(FILE_ID_OR_FILE_PATH_IN_FILE_CABINET);
var originalContent = original.getValue(); //Return the value (base64 encoded for binary types) of the file
var updated = nlapiCreateFile(original.getName(), FILE_TYPE, UPDATED_FILE_CONTENTS);
updated.setFolder(original.getFolder());
nlapiSubmitFile(updated);
I experienced a similar error when trying to modify a file using SuiteScript in Netsuite at the server-side. I was using the way explained in the documentation, where they say copying a new file through file.copy() with conflictResolution: file.ConflictResolution.OVERWRITE. However, that way didn't work for me as it neither created the file nor overwrote it. Finally, I use the following form to get it working:
...
let fileNew = file.create({
name: 'same_name_of_the_original_file',
fileType: file.Type.PLAINTEXT, // change it depending the file type you will create
contents: credentials.body,
});
fileNew.folder = folder_id;
let fileId = fileNew.save();
...
So, the key is to change the folder and saving it after the file is created. After that, saving the file would overwrite the original.

Resources