Php 如何在magento中创建可配置的cron计划?
我一直试图通过管理站点在Magento中创建一个可配置的Cron计划。我了解到,如果config.xml Magento中没有指定Cron计划,请在core_config_数据表中搜索它。 我可以填充core_config_数据表,但没有创建计划。 这是我的文件结构 [模块为Saeconnector,位于app/code/local/Wolfsellers/Saeconnector][1] 这是我的config.xml文件:Php 如何在magento中创建可配置的cron计划?,php,xml,magento,cron,Php,Xml,Magento,Cron,我一直试图通过管理站点在Magento中创建一个可配置的Cron计划。我了解到,如果config.xml Magento中没有指定Cron计划,请在core_config_数据表中搜索它。 我可以填充core_config_数据表,但没有创建计划。 这是我的文件结构 [模块为Saeconnector,位于app/code/local/Wolfsellers/Saeconnector][1] 这是我的config.xml文件: <config> <modules>
<config>
<modules>
<Wolfsellers_Saeconnector>
<version>0.0.1</version>
</Wolfsellers_Saeconnector>
</modules>
<global>
<models>
<wolfsellers_saeconnector>
<resourceModel>wolfsellers_saeconnector_resource</resourceModel>
<class>Wolfsellers_Saeconnector_Model</class>
</wolfsellers_saeconnector>
<wolfsellers_saeconnector_resource>
<entities>
<saewolf>
<table>sae_wolf</table>
</saewolf>
<saeprodwolf>
<table>sae_prod_wolf</table>
</saeprodwolf>
<saewolfpath>
<table>sae_path_wolf</table>
</saewolfpath>
<saewolfconf>
<table>sae_wolf_conf</table>
</saewolfconf>
</entities>
</wolfsellers_saeconnector_resource>
</models>
<resources>
<wolfsellers_saeconnector_setup>
<setup>
<module>Wolfsellers_Saeconnector</module>
<class>Mage_Core_Model_Resource_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</wolfsellers_saeconnector_setup>
</resources>
<helpers>
<saeconnector>
<class>Wolfsellers_Saeconnector_Helper</class>
</saeconnector>
</helpers>
<blocks>
<wolfsellers_saeconnector>
<class>Wolfsellers_Saeconnector_Block</class>
</wolfsellers_saeconnector>
</blocks>
</global>
<adminhtml>
<acl>
<resources>
<admin>
<children>
<system>
<children>
<config>
<children>
<saeconnector_options>
<title>Custom Configuration Section</title>
</saeconnector_options>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
</adminhtml>
<crontab>
<jobs>
<wolfsellers_saeconnector>
<run>
<model>wolfsellers_saeconnector/observer::setStatus</model>
</run>
</wolfsellers_saeconnector>
</jobs>
</crontab>
}
我的数据库核心配置日期设置如下:
[这两行是由Cron.php创建的][2]
我只想创建一个可配置的cron时间表,如果有其他方法或者我做错了什么,可以帮助或引导我走上真理和严格的道路,请提前感谢 希望这能帮助你谢谢你,我举了那个例子,但我什么也没发生…希望这能帮助你谢谢你,我举了那个例子,但我什么也没发生。。。
<config>
<tabs>
<saeconnector translate="label" module="saeconnector">
<label>Wolfsellers</label>
<sort_order>5</sort_order>
</saeconnector>
</tabs>
<sections>
<saeconnector_options translate="label" module="saeconnector">
<label>Configuration</label>
<tab>saeconnector</tab>
<frontend_type>text</frontend_type>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
<groups>
<db_conf translate="label">
<label>SAE-Database Configuration</label>
<frontend_type>text</frontend_type>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<fields>
<user>
<label>Login user:</label>
<frontend_type>text</frontend_type>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
<comment>SAE database login user.</comment>
</user>
<login>
<label>Login password:</label>
<frontend_type>password</frontend_type>
<sort_order>2</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
<comment>SAE database login password.</comment>
</login>
<path>
<label>Database URL:</label>
<frontend_type>text</frontend_type>
<sort_order>3</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
<comment>SAE database URL.</comment>
</path>
</fields>
</db_conf>
<configurable_cron translate="label">
<label>Configuration - Sync</label>
<frontend_type>text</frontend_type>
<sort_order>2</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
<fields>
<enable_sync translate="label">
<label>Enable</label>
<frontend_type>select</frontend_type>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
<source_model>wolfsellers_saeconnector/yesno</source_model>
</enable_sync>
<time translate="label">
<label>Start Time</label>
<frontend_type>time</frontend_type>
<sort_order>2</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
<depends>
<enable_sync>1</enable_sync>
</depends>
</time>
<frequency translate="label">
<label>Frequency</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_cron_frequency</source_model>
<backend_model>wolfsellers_saeconnector/system_config_backend_cron</backend_model>
<sort_order>3</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
<depends>
<enable_sync>1</enable_sync>
</depends>
</frequency>
<recipient translate="label">
<label>Error Email Recipient</label>
<frontend_type>text</frontend_type>
<sort_order>4</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
<depends>
<enable_sync>1</enable_sync>
</depends>
</recipient>
<sender translate="label">
<label>Error Email Sender</label>
<frontend_type>text</frontend_type>
<sort_order>5</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
<depends>
<enable_sync>1</enable_sync>
</depends>
</sender>
</fields>
</configurable_cron>
<inv_conf translate="label">
<label>Inventario</label>
<frontend_type>text</frontend_type>
<sort_order>3</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
<fields>
<enable_sync_inv>
<label>Enable sync inventory</label>
<frontend_type>select</frontend_type>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
<source_model>wolfsellers_saeconnector/yesno</source_model>
</enable_sync_inv>
<inv_attr>
<label>Attributes to sync</label>
<frontend_type>multiselect</frontend_type>
<source_model>wolfsellers_saeconnector/productattr</source_model>
<sort_order>2</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
<depends>
<enable_sync_inv>1</enable_sync_inv>
</depends>
</inv_attr>
</fields>
</inv_conf>
<client_conf translate="label">
<label>Clientes</label>
<frontend_type>text</frontend_type>
<sort_order>4</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
<fields>
<enable_sync_client>
<label>Enable sync client</label>
<frontend_type>select</frontend_type>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
<source_model>wolfsellers_saeconnector/yesno</source_model>
</enable_sync_client>
<client_attr>
<label>Attributes to sync</label>
<frontend_type>multiselect</frontend_type>
<source_model>wolfsellers_saeconnector/clientattr</source_model>
<sort_order>2</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
<depends>
<enable_sync_client>1</enable_sync_client>
</depends>
</client_attr>
</fields>
</client_conf>
</groups>
</saeconnector_options>
</sections>
class Wolfsellers_Saeconnector_Model_System_Config_Backend_Cron extends Mage_Core_Model_Config_Data{
const CRON_STRING_PATH = 'crontab/jobs/wolfsellers_saeconnector/schedule/cron_expr';
const CRON_MODEL_PATH = 'crontab/jobs/wolfsellers_saeconnector/run/model';
protected function _afterSave()
{
$enabled = $this->getData('groups/configurable_cron/fields/enable_sync/value');
$frequncy = $this->getData('groups/configurable_cron/fields/frequency/value');
$time = $this->getData('groups/configurable_cron/fields/time/value');
$frequencyDaily = Mage_Adminhtml_Model_System_Config_Source_Cron_Frequency::CRON_DAILY;
$frequencyWeekly = Mage_Adminhtml_Model_System_Config_Source_Cron_Frequency::CRON_WEEKLY;
$frequencyMonthly = Mage_Adminhtml_Model_System_Config_Source_Cron_Frequency::CRON_MONTHLY;
$cronDayOfWeek = date('N');
$cronExprArray = array(
intval($time[1]), # Minute
intval($time[0]), # Hour
($frequncy == $frequencyMonthly) ? '1' : '*', # Day of the Month
'*', # Month of the Year
($frequncy == $frequencyWeekly) ? '1' : '*', # Day of the Week
);
$cronExprString = join(' ', $cronExprArray);
try {
Mage::getModel('core/config_data')
->load(self::CRON_STRING_PATH, 'path')
->setValue($cronExprString)
->setPath(self::CRON_STRING_PATH)
->save();
Mage::getModel('core/config_data')
->load(self::CRON_MODEL_PATH, 'path')
->setValue((string) Mage::getConfig()->getNode(self::CRON_MODEL_PATH))
->setPath(self::CRON_MODEL_PATH)
->save();
Mage::getConfig()->cleanCache();
} catch (Exception $e) {
throw new Exception(Mage::helper('cron')->__('Unable to save the cron expression.'));
}
}