2016-05-17, 05:50:21
If someone needs to test how News Manager works with a big number of posts, you can use this quick and dirty script:
Copypaste and save it in your site's root folder with the name you wish, e.g. nm-test-posts.php
Edit the first lines of the script: change the number of posts ($NUM), slug prefix ($SLUG), start/end dates...
Then open it in your browser, e.g.: SITE/nm-test-posts.php
You should see a "xxx test posts generated." message and a "Delete them" link.
That's it. Now you can test how it works both in backend and frontend (maybe in another browser window/tab)
To delete the test posts, you can use the "delete them" link that the script displayed, or else visit SITE/nm-test-posts.php?delete and browse again to the NM admin panel (to refresh)
Code:
<?php
$DIR = 'data/posts';
$NUM = 1000;
$SLUG = 'nm-test-post-';
$STARTDATE = strtotime('1 Aug 2014');
$ENDDATE = strtotime('15 May 2016');
if (isset($_GET['delete'])) {
foreach(glob($DIR.'/'.$SLUG.'*.xml') as $file)
unlink($file);
?>Test posts deleted. - <a href="<?php echo basename($_SERVER['PHP_SELF']); ?>">Generate test posts</a><?php
} else {
for ($i = 1; $i <= $NUM; $i++) {
$str = '<?xml version="1.0" encoding="UTF-8"?><item>
<title><![CDATA[News Manager test post #'.
strval($i)
.']]></title>
<date><![CDATA['.
date("F j, Y, g:i a",$STARTDATE+$i*($ENDDATE-$STARTDATE)/$NUM)
.']]></date>
<tags><![CDATA[nm-test-tag]]></tags>
<private><![CDATA[]]></private>
<image><![CDATA[]]></image>
<content><![CDATA[
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam velit enim, eleifend et odio ut, pulvinar dictum lectus. Praesent vitae vulputate orci, vitae pellentesque sapien. Praesent commodo orci eu erat egestas, sit amet finibus sapien eleifend. Maecenas at ante tincidunt, luctus ex eu, dapibus dolor. Phasellus feugiat vehicula sapien, sit amet dictum dolor interdum at. Vivamus a risus hendrerit, tristique mauris quis, lacinia dolor. Ut sem justo, suscipit facilisis lectus id, porttitor vehicula nunc. Quisque metus enim, sodales at velit ac, sollicitudin imperdiet augue. Morbi ligula velit, mattis in lacinia eget, gravida eu massa. Quisque libero nisi, auctor non nibh quis, tristique congue risus. Vestibulum elementum eros risus, at cursus quam ullamcorper in.
]]></content>
</item>';
file_put_contents($DIR.'/'.$SLUG.strval($i).'.xml', $str);
}
echo $i-1; ?> test posts generated. <a href="<?php echo basename($_SERVER['PHP_SELF']); ?>?delete">Delete them</a>
<?php }
@unlink('data/other/news_manager/posts.xml');
// end of file
Copypaste and save it in your site's root folder with the name you wish, e.g. nm-test-posts.php
Edit the first lines of the script: change the number of posts ($NUM), slug prefix ($SLUG), start/end dates...
Then open it in your browser, e.g.: SITE/nm-test-posts.php
You should see a "xxx test posts generated." message and a "Delete them" link.
That's it. Now you can test how it works both in backend and frontend (maybe in another browser window/tab)
To delete the test posts, you can use the "delete them" link that the script displayed, or else visit SITE/nm-test-posts.php?delete and browse again to the NM admin panel (to refresh)