Пример #1
0
 public function __construct(array $config = array())
 {
     $config['rootNode'] = 'trl';
     $config['xpath'] = '/trl';
     $config['topNode'] = 'text';
     parent::__construct($config);
 }
 public function checkIdsAction()
 {
     Kwf_Events_ModelObserver::getInstance()->disable();
     $models = array(Kwf_Model_Abstract::getInstance('Kwf_Trl_Model_Kwf'), Kwf_Model_Abstract::getInstance('Kwf_Trl_Model_Web'));
     foreach ($models as $m) {
         while ($m instanceof Kwf_Model_Proxy) {
             $m = $m->getProxyModel();
         }
         if (!file_exists($m->getFilePath())) {
             continue;
         }
         $ids = array();
         $duplicate = 0;
         $xml = simplexml_load_file($m->getFilePath());
         $maxId = 0;
         foreach ($xml->text as $row) {
             $maxId = max($maxId, (int) $row->id);
         }
         foreach ($xml->text as $row) {
             $id = (int) $row->id;
             if (in_array($id, $ids)) {
                 echo $m->getFilePath() . ": {$id} doppelt\n";
                 $duplicate++;
                 $row->id = ++$maxId;
                 continue;
             }
             $ids[] = $id;
         }
         if (!$duplicate) {
             echo $m->getFilePath() . ": alles ok\n";
         } else {
             file_put_contents($m->getFilePath(), Kwf_Model_Xml::asPrettyXML($xml->asXML()));
         }
     }
     exit;
 }
Пример #3
0
 public function testUpdateValueToNull()
 {
     $model = new Kwf_Model_Xml(array('xpath' => '/trl', 'topNode' => 'text', 'xmlContent' => '<trl><text><id>1</id><en>foo</en><de>dings</de></text></trl>'));
     $row1 = $model->createRow(array('en' => 'foobar', 'de' => 'dingsbums', 'context' => 'hallo'));
     $row1->save();
     $row1->context = null;
     $row1->save();
     $row = $model->getRow($model->select()->whereEquals('en', 'foobar')->whereNull('context'));
     $this->assertEquals('dingsbums', $row->de);
     $row = $model->getRow($model->select()->whereEquals('en', 'foobar')->whereEquals('context', ''));
     $this->assertNull($row);
     $model = new Kwf_Model_Xml(array('xpath' => '/trl', 'topNode' => 'text', 'xmlContent' => $model->getXmlContentString()));
     $row = $model->getRow($model->select()->whereEquals('en', 'foobar')->whereNull('context'));
     $this->assertEquals('dingsbums', $row->de);
     $row = $model->getRow($model->select()->whereEquals('en', 'foobar')->whereEquals('context', ''));
     $this->assertNull($row);
 }